Tabelle e intervalli
Introduzione
A volte si crea una tabella in Microsoft Excel e non si desidera continuare a lavorare con la funzionalità di tabella che la accompagna. Piuttosto, si desidera qualcosa che assomigli a una tabella. Per mantenere i dati in una tabella senza perdere la formattazione, convertire la tabella in un intervallo regolare di dati. Aspose.Cells per Python via .NET supporta questa funzione di Microsoft Excel per tabelle e oggetti elenco.
Utilizzando Microsoft Excel
Utilizzare la funzionalità Converti in Intervallo per convertire rapidamente una tabella in un intervallo senza perdere la formattazione. In Microsoft Excel 2007/2010:
- Fare clic ovunque nella tabella per garantire che la cella attiva sia in una colonna della tabella.
- Sulla scheda Design, nel gruppo Strumenti, fare clic su Converti in intervallo.
Usando Aspose.Cells per 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") |
Converti Tabella in Intervallo con Opzioni
Aspose.Cells per Python via .NET fornisce opzioni aggiuntive durante la conversione di una tabella in intervallo tramite la classe TableToRangeOptions. La classe TableToRangeOptions fornisce la proprietà last_row che permette di impostare l’indice finale della riga della tabella. La formattazione della tabella sarà mantenuta fino all’indice di riga specificato e il resto della formattazione verrà rimosso.
Il codice di esempio qui sotto dimostra l’uso della classe 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") |