テーブルおよび範囲

紹介

Microsoft Excelでテーブルを作成し、その機能を使用せずにテーブルのデータを保持したい場合があります。代わりに、テーブルのように見えるものが欲しい場合があります。フォーマットを失わずにテーブル内のデータを保持するには、テーブルを通常のデータの範囲に変換します。 Aspose.Cells for Python via .NETは、このMicrosoft Excelのテーブルとリストオブジェクトの機能をサポートしています。

Microsoft Excel の使用

表をフォーマットを保持したまま範囲に素早く変換するには、範囲に変換 機能を使用します。Microsoft Excel 2007/2010では:

  1. 表内のどこかをクリックして、アクティブなセルが表の列内にあることを確認します。
  2. デザイン タブの ツール グループで、範囲に変換 をクリックします。

Aspose.Cells for Python via .NETを使用して

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Open an existing file that contains a table/list object in it
wb = Workbook(dataDir + "book1.xlsx")
# Convert the first table/list object (from the first worksheet) to normal range
wb.worksheets[0].list_objects[0].convert_to_range()
# Save the file
wb.save(dataDir + "output.xlsx")

オプションで範囲にテーブルを変換

Aspose.Cells for Python via .NETは、TableToRangeOptionsクラスを通じてテーブルを範囲に変換する際の追加オプションを提供します。TableToRangeOptionsクラスはlast_rowプロパティを提供し、これを使用してテーブルの最後の行インデックスを設定できます。指定された行インデックスまでテーブルのフォーマットが維持され、それ以降のフォーマットは削除されます。

以下のサンプルコードは、TableToRangeOptions クラスの使用例を示しています。

from aspose.cells import Workbook
from aspose.cells.tables import TableToRangeOptions
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Open an existing file that contains a table/list object in it
workbook = Workbook(dataDir + "book1.xlsx")
options = TableToRangeOptions()
options.last_row = 5
# Convert the first table/list object (from the first worksheet) to normal range
workbook.worksheets[0].list_objects[0].convert_to_range(options)
# Save the file
workbook.save(dataDir + "output.xlsx")