Anpassen der Zeilenhöhe und Spaltenbreite
Arbeiten mit Zeilen
Anpassen der Zeilenhöhe
Aspose.Cells bietet eine Klasse, Workbook, die eine Microsoft Excel-Datei repräsentiert. Die Klasse Workbook enthält eine WorksheetCollection, die den Zugriff auf jedes Arbeitsblatt in der Excel-Datei ermöglicht. Ein Arbeitsblatt wird durch die Klasse Worksheet repräsentiert. Die Klasse Worksheet bietet eine Cells-Sammlung, die alle Zellen im Arbeitsblatt repräsentiert. Die Cells-Sammlung bietet verschiedene Methoden zur Verwaltung von Zeilen oder Spalten in einem Arbeitsblatt. Einige davon werden unten genauer erläutert.
Die Höhe einer Zeile festlegen
Es ist möglich, die Höhe einer einzelnen Zeile durch Aufrufen der Methode SetRowHeight der Cells-Sammlung festzulegen. Die Methode SetRowHeight nimmt die folgenden Parameter wie folgt entgegen:
- Zeilenindex, der Index der Zeile, deren Höhe geändert wird.
- Zeilenhöhe, die auf die Zeile anzuwendende Zeilenhöhe.
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 sampleRowsAndColumns = dirPath + u"sampleRowsAndColumns.xlsx"; | |
//Path of output excel file | |
U16String outputRowsAndColumns = outPath + u"outputRowsAndColumns.xlsx"; | |
//Read input excel file | |
Workbook workbook(sampleRowsAndColumns); | |
//Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.GetWorksheets().Get(0); | |
//Setting the height of the second row to 35 | |
worksheet.GetCells().SetRowHeight(1, 35); | |
//Save the Excel file. | |
workbook.Save(outputRowsAndColumns); | |
Aspose::Cells::Cleanup(); |
Die Höhe aller Zeilen in einem Arbeitsblatt festlegen
Wenn Entwickler die gleiche Zeilenhöhe für alle Zeilen in einem Arbeitsblatt festlegen müssen, können sie dies mit der Methode SetStandardHeight der Cells-Sammlung tun.
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 sampleRowsAndColumns = dirPath + u"sampleRowsAndColumns.xlsx"; | |
//Path of output excel file | |
U16String outputRowsAndColumns = outPath + u"outputRowsAndColumns.xlsx"; | |
//Read input excel file | |
Workbook workbook(sampleRowsAndColumns); | |
//Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.GetWorksheets().Get(0); | |
// Setting the height of all rows in the worksheet to 25 | |
worksheet.GetCells().SetStandardHeight(25); | |
//Save the Excel file. | |
workbook.Save(outputRowsAndColumns); | |
Aspose::Cells::Cleanup(); |
Arbeiten mit Spalten
Einstellen der Breite einer Spalte
Legen Sie die Breite einer Spalte fest, indem Sie die Methode SetColumnWidth der Sammlung Cells aufrufen. Die Methode SetColumnWidth verwendet die folgenden Parameter:
- Spaltenindex, der Index der Spalte, deren Breite geändert wird.
- Spaltenbreite, die gewünschte Spaltenbreite.
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 sampleRowsAndColumns = dirPath + u"sampleRowsAndColumns.xlsx"; | |
//Path of output excel file | |
U16String outputRowsAndColumns = outPath + u"outputRowsAndColumns.xlsx"; | |
//Read input excel file | |
Workbook workbook(sampleRowsAndColumns); | |
//Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.GetWorksheets().Get(0); | |
//Setting the width of the second column to 56.5 | |
worksheet.GetCells().SetColumnWidth(1, 56.5); | |
//Save the Excel file. | |
workbook.Save(outputRowsAndColumns); | |
Aspose::Cells::Cleanup(); |
Einstellen der Breite aller Spalten in einem Arbeitsblatt
Um dieselbe Spaltenbreite für alle Spalten im Arbeitsblatt festzulegen, verwenden Sie die Methode SetStandardWidth der Sammlung Cells.
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 sampleRowsAndColumns = dirPath + u"sampleRowsAndColumns.xlsx"; | |
//Path of output excel file | |
U16String outputRowsAndColumns = outPath + u"outputRowsAndColumns.xlsx"; | |
//Read input excel file | |
Workbook workbook(sampleRowsAndColumns); | |
//Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.GetWorksheets().Get(0); | |
//Setting the width of all columns in the worksheet to 20.5 | |
worksheet.GetCells().SetStandardWidth(20.5); | |
//Save the Excel file. | |
workbook.Save(outputRowsAndColumns); | |
Aspose::Cells::Cleanup(); |