ブック内の名前付き範囲の操作
可能な使用シナリオ
Aspose.Cells は既存の名前付き範囲の操作をサポートしています。すべての既存の名前付き範囲には Workbook.GetWorksheets().GetNames() コレクションからアクセスできます。名前付き範囲にアクセスしたら、 GetFullText および GetRefersTo などのさまざまなメソッドを変更することができます。
ブック内の名前付き範囲の操作
以下のサンプルコードでは、ソースエクセルファイル 内の最初の名前付き範囲を読み込み、その FullText および RefersTo プロパティをコンソールに出力します。その後、RefersTo
プロパティを変更し、 出力エクセルファイル を保存します。
サンプルコード
Aspose::Cells::Startup(); | |
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input | |
U16String dirPath(u""); | |
//Path of output | |
U16String outPath(u""); | |
//Path of input excel file | |
U16String sampleManipulateNamedRangeInWorkbook = dirPath + u"sampleManipulateNamedRangeInWorkbook.xlsx"; | |
//Path of output excel file | |
U16String outputManipulateNamedRangeInWorkbook = outPath + u"outputManipulateNamedRangeInWorkbook.xlsx"; | |
//Create a workbook | |
Workbook wb(sampleManipulateNamedRangeInWorkbook); | |
//Read the named range created above from names collection | |
Name nm = wb.GetWorksheets().GetNames().Get(0); | |
//Print its FullText and RefersTo members | |
std::cout << "Full Text : " << nm.GetFullText().ToUtf8() << std::endl; | |
std::cout << "Refers To : " << nm.GetRefersTo().ToUtf8() << std::endl; | |
//Manipulate the RefersTo property of NamedRange | |
nm.SetRefersTo(u"=Sheet1!$D$5:$J$10"); | |
//Save the workbook in xlsx format | |
wb.Save(outputManipulateNamedRangeInWorkbook, SaveFormat::Xlsx); | |
Aspose::Cells::Cleanup() |
コンソール出力
次のコンソール出力は、上記のコード内の既存のNamed RangeのFullText と RefersTo メンバーの値を出力します。
Full Text: TestRange
Refers To: =Sheet1!$D$3:$G$6