Justera radhöjd och kolumnbredd
Arbeta med rader
Justering av radhöjd
Aspose.Cells tillhandahåller en klass,IArbetsbok som representerar en Microsoft Excel-fil. DeIArbetsbok klass innehåller enIWorksheetCollectionsom ger åtkomst till varje kalkylblad i Excel-filen. Ett arbetsblad representeras avIArbetsblad klass. DeIArbetsblad klass ger enICells samling som representerar alla celler i kalkylbladet. DeICellssamling innehåller flera metoder för att hantera rader eller kolumner i ett kalkylblad. Några av dessa diskuteras mer i detalj nedan.
Ställa in höjden på en rad
Det är möjligt att ställa in höjden på en enstaka rad genom att anropaICells samlingensSetRowHeight metod. DeSetRowHeightmetoden tar följande parametrar enligt följande:
- Radindex, indexet för raden som du ändrar höjden på.
- Radhöjd, radhöjden som ska tillämpas på raden.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input excel file | |
StringPtr sampleRowsAndColumns = dirPath->StringAppend(new String("sampleRowsAndColumns.xlsx")); | |
//Path of output excel file | |
StringPtr outputRowsAndColumns = outPath->StringAppend(new String("outputRowsAndColumns.xlsx")); | |
//Read input excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleRowsAndColumns); | |
//Accessing the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
//Setting the height of the second row to 35 | |
worksheet->GetICells()->SetRowHeight(1, 35); | |
//Save the Excel file. | |
workbook->Save(outputRowsAndColumns); |
Ställa in höjden på alla rader i ett kalkylblad
Om utvecklare behöver ställa in samma radhöjd för alla rader i kalkylbladet kan de göra det genom att användaStäll in Standardhöjd metod förICellssamling.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input excel file | |
StringPtr sampleRowsAndColumns = dirPath->StringAppend(new String("sampleRowsAndColumns.xlsx")); | |
//Path of output excel file | |
StringPtr outputRowsAndColumns = outPath->StringAppend(new String("outputRowsAndColumns.xlsx")); | |
//Read input excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleRowsAndColumns); | |
//Accessing the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Setting the height of all rows in the worksheet to 25 | |
worksheet->GetICells()->SetStandardHeight(25); | |
//Save the Excel file. | |
workbook->Save(outputRowsAndColumns); |
Arbeta med kolumner
Ställa in bredden på en kolumn
Ställ in bredden på en kolumn genom att anropaICells samlingensSetColumnWidth metod. DeSetColumnWidthmetoden tar följande parametrar:
- Kolumnindex, indexet för kolumnen som du ändrar bredden på.
- Kolumnbredd, önskad kolumnbredd.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input excel file | |
StringPtr sampleRowsAndColumns = dirPath->StringAppend(new String("sampleRowsAndColumns.xlsx")); | |
//Path of output excel file | |
StringPtr outputRowsAndColumns = outPath->StringAppend(new String("outputRowsAndColumns.xlsx")); | |
//Read input excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleRowsAndColumns); | |
//Accessing the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
//Setting the width of the second column to 56.5 | |
worksheet->GetICells()->SetColumnWidth(1, 56.5); | |
//Save the Excel file. | |
workbook->Save(outputRowsAndColumns); |
Ställa in bredden på alla kolumner i ett kalkylblad
För att ställa in samma kolumnbredd för alla kolumner i kalkylbladet, användICells samlingensSetStandardWidthmetod.
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input excel file | |
StringPtr sampleRowsAndColumns = dirPath->StringAppend(new String("sampleRowsAndColumns.xlsx")); | |
//Path of output excel file | |
StringPtr outputRowsAndColumns = outPath->StringAppend(new String("outputRowsAndColumns.xlsx")); | |
//Read input excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(sampleRowsAndColumns); | |
//Accessing the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
//Setting the width of all columns in the worksheet to 20.5 | |
worksheet->GetICells()->SetStandardWidth(20.5); | |
//Save the Excel file. | |
workbook->Save(outputRowsAndColumns); |