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

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

Изменение высоты строки

Aspose.Cells предоставляет класс Workbook, который представляет собой файл Microsoft Excel. Класс Workbook содержит WorksheetCollection, который позволяет получить доступ ко всем листам Excel файла. Лист представлен классом Worksheet. Класс Worksheet предоставляет коллекцию Cells, которая представляет все ячейки на листе. Коллекция Cells предоставляет несколько методов для управления строками или столбцами на листе. Некоторые из них подробно обсуждаются ниже.

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

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

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

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

Если разработчикам нужно установить одинаковую высоту строки для всех строк на листе, они могут сделать это, используя метод SetStandardHeight коллекции 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 height of all rows in the worksheet to 25
worksheet.GetCells().SetStandardHeight(25);
//Save the Excel file.
workbook.Save(outputRowsAndColumns);
Aspose::Cells::Cleanup();

Работа с колонками

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

Установите ширину колонки, вызвав метод SetColumnWidth коллекции Cells. Метод SetColumnWidth принимает следующие параметры:

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

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

Чтобы установить одинаковую ширину колонки для всех колонок на листе, используйте метод SetStandardWidth коллекции 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();