Manipolare Intervalli con Nome in un Workbook
Possibili Scenari di Utilizzo
Aspose.Cells supporta la manipolazione degli intervalli con nome esistenti. Tutti gli intervalli con nome esistenti possono essere accessibili dalla collezione Workbook.GetWorksheets().GetNames(). Una volta che si accede all’intervallo con nome, è possibile modificare i vari metodi come ad es. GetFullText e GetRefersTo.
Manipolare l’intervallo di celle con nome in un documento di lavoro
Il seguente codice di esempio legge il primo intervallo di celle con nome all’interno del file Excel di origine e ne stampa le proprietà FullText e RefersTo sulla console. Successivamente modifica la proprietà RefersTo
e salva il file Excel di output.
Codice di Esempio
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() |
Output della console
Il seguente output della console stampa i valori dei membri FullText e RefersTo dell' Intervallo di Celle con Nome esistente nel codice precedente.
Full Text: TestRange
Refers To: =Sheet1!$D$3:$G$6