Tabelle e intervalli
introduzione
A volte crei una tabella in Microsoft Excel e non vuoi continuare a lavorare con la funzionalità della tabella che ne deriva. Invece, vuoi qualcosa che assomigli a un tavolo. Per mantenere i dati in una tabella senza perdere la formattazione, convertire la tabella in un normale intervallo di dati. Aspose.Cells supporta questa funzionalità di Microsoft Excel per tabelle e oggetti elenco.
Utilizzando Microsoft Excel
Usa ilConverti in intervallo funzionalità per convertire rapidamente una tabella in un intervallo senza perdere la formattazione. In Microsoft Excel 2007/2010:
- Fare clic in un punto qualsiasi della tabella per assicurarsi che la cella attiva sia in una colonna della tabella.
- SulDesign scheda, nelUtensili gruppo, fare clicConverti in intervallo.
Utilizzando Aspose.Cells
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open an existing file that contains a table/list object in it | |
Workbook wb = new Workbook(dataDir + "book1.xlsx"); | |
// Convert the first table/list object (from the first worksheet) to normal range | |
wb.Worksheets[0].ListObjects[0].ConvertToRange(); | |
// Save the file | |
wb.Save(dataDir + "output.xlsx"); |
Converti tabella in intervallo con le opzioni
Aspose.Cells fornisce opzioni aggiuntive durante la conversione della tabella in intervallo attraverso ilTableToRangeOptions classe. IlTableToRangeOptionsla classe fornisceUltima rigaproprietà che consente di impostare l’ultimo indice della riga della tabella. La formattazione della tabella verrà mantenuta fino all’indice di riga specificato e il resto della formattazione verrà rimosso.
Il codice di esempio fornito di seguito dimostra l’uso diTableToRangeOptionsclasse.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open an existing file that contains a table/list object in it | |
Workbook workbook = new Workbook(dataDir + "book1.xlsx"); | |
TableToRangeOptions options = new TableToRangeOptions(); | |
options.LastRow = 5; | |
// Convert the first table/list object (from the first worksheet) to normal range | |
workbook.Worksheets[0].ListObjects[0].ConvertToRange(options); | |
// Save the file | |
workbook.Save(dataDir + "output.xlsx"); |