Tabeller och Intervall
Introduktion
Ibland skapar du en tabell i Microsoft Excel och vill inte fortsätta arbeta med tabellfunktionaliteten som medföljer den. Istället vill du ha något som ser ut som en tabell. För att behålla data i en tabell utan att förlora formatering, konvertera tabellen till ett vanligt datarange. Aspose.Cells stöder denna funktion i Microsoft Excels tabeller och listobjekt.
Använda Microsoft Excel
Använd Konvertera till område-funktionen för att snabbt konvertera en tabell till en mängd utan att förlora formateringen. I Microsoft Excel 2007/2010:
- Klicka var som helst i tabellen för att se till att den aktiva cellen är i en tabellkolumn.
- På fliken Utformning, i gruppen Verktyg, klicka på Konvertera till område.
Använda Aspose.Cells
Följande kodsnutt visar samma funktionalitet med hjälp av Aspose.Cells.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
Aspose::Cells::Startup(); | |
//Path of input | |
U16String dirPath(u""); | |
//Path of output | |
U16String outPath(u""); | |
// Instantiate a Workbook object and open an Excel file | |
Workbook workbook(dirPath + u"sample.xlsx"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.GetWorksheets().Get(0); | |
// Get the List objects collection in the first worksheet. | |
ListObjectCollection listObjects = worksheet.GetListObjects(); | |
// Convert the first table/list object (from the first worksheet) to normal range | |
listObjects.Get(0).ConvertToRange(); | |
// Saving the Excel file | |
workbook.Save(outPath + u"ConvertTableToRange_out.xls"); | |
Aspose::Cells::Cleanup(); |