Настройка высоты строки и ширины столбца

Работа со строками

Регулировка высоты строки

Aspose.Cells предоставляет класс,IWorkbook который представляет собой файл Excel Microsoft.IWorkbook класс содержитIWorksheetCollectionкоторый позволяет получить доступ к каждому рабочему листу в файле Excel. Рабочий лист представленрабочий лист учебный класс.рабочий лист класс предоставляетICells коллекция, представляющая все ячейки рабочего листа.ICellscollection предоставляет несколько методов для управления строками или столбцами на листе. Некоторые из них обсуждаются ниже более подробно.

Установка высоты строки

Можно установить высоту одной строки, вызвав функциюICells коллекцияSetRowHeight метод.SetRowHeightМетод принимает следующие параметры следующим образом:

  • Индекс строки, индекс строки, высоту которой вы меняете.
  • Высота строки, высота строки, применяемая к строке.
//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);

Установка высоты всех строк на листе

Если разработчикам нужно установить одинаковую высоту для всех строк на листе, они могут сделать это с помощьюSetStandardHeight методICellsколлекция.

//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);

Работа со столбцами

Установка ширины столбца

Задайте ширину столбца, вызвав методICells коллекцияSetColumnWidth метод.SetColumnWidthметод принимает следующие параметры:

  • Индекс столбца, индекс столбца, ширину которого вы меняете.
  • Ширина колонки, желаемая ширина столбца.
//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);

Установка ширины всех столбцов на листе

Чтобы установить одинаковую ширину столбца для всех столбцов на листе, используйтеICells коллекцияSetStandardWidthметод.

//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);