Justering av radhöjd och kolumnbredd
Arbeta med rader
Justera radhöjd
Aspose.Cells tillhandahåller en klass, Workbook som representerar en Microsoft Excel-fil. Workbook klassen innehåller en WorksheetCollection som möjliggör åtkomst till varje arbetsblad i Excel-filen. Ett arbetsblad representeras av Worksheet klassen. Worksheet klassen tillhandahåller en Cells samling som representerar alla celler i arbetsbladet. Cells samlingen tillhandahåller flera metoder för att hantera rader eller kolumner i ett arbetsblad. Några av dessa diskuteras nedan mer detaljerat.
Inställning av radhöjd
Det är möjligt att ange höjden på en enskild rad genom att anropa Cells samlingens SetRowHeight metod. SetRowHeight metoden tar följande parametrar som följer:
- Radindex, index för den rad vars höjd du ändrar.
- Radhöjd, radhöjden som ska tillämpas på raden.
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(); |
Inställning av höjden på alla rader i ett arbetsblad
Om utvecklare behöver ange samma radhöjd för alla rader i arbetsbladet kan de göra det genom att använda SetStandardHeight metoden i Cells samlingen.
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(); |
Arbeta med kolumner
Inställning av bredden på en kolumn
Ställ in bredden på en kolumn genom att anropa Cells samlingens SetColumnWidth metod. SetColumnWidth metoden tar följande parametrar:
- Kolumnindex, index för den kolumn vars bredd du ändrar.
- Kolumnbredd, önskad kolumnbredd.
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(); |
Inställning av bredden på alla kolumner i ett arbetsblad
För att ställa in samma kolumnbredd för alla kolumner i arbetsbladet, använd SetStandardWidth metod i Cells samlingen.
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(); |