Regolazione dell altezza della riga e della larghezza della colonna

Lavorare con le righe

Regolazione dell’altezza della riga

Aspose.Cells fornisce una classe, Workbook che rappresenta un file Microsoft Excel. La classe Workbook contiene una WorksheetCollection che consente l’accesso a ciascun foglio di lavoro nel file Excel. Un foglio di lavoro è rappresentato dalla classe Worksheet. La classe Worksheet fornisce una raccolta di Cells che rappresenta tutte le celle nel foglio di lavoro. La raccolta di Cells fornisce diversi metodi per gestire righe o colonne in un foglio di lavoro. Alcuni di questi vengono discussi di seguito in maggior dettaglio.

Impostazione dell’altezza di una riga

E' possibile impostare l’altezza di una singola riga chiamando il metodo SetRowHeight della raccolta di Cells. Il metodo SetRowHeight prende i seguenti parametri come segue:

  • Indice di riga, l’indice della riga a cui si sta modificando l’altezza.
  • Altezza della riga, l’altezza della riga da applicare alla riga.
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();

Impostazione dell’altezza di tutte le righe in un foglio di lavoro

Se gli sviluppatori hanno bisogno di impostare la stessa altezza di riga per tutte le righe nel foglio di lavoro, possono farlo utilizzando il metodo SetStandardHeight della raccolta di 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();

Lavorare con colonne

Impostazione della larghezza di una colonna

Imposta la larghezza di una colonna chiamando il metodo SetColumnWidth della raccolta di Cells. Il metodo SetColumnWidth accetta i seguenti parametri:

  • Indice di colonna, l’indice della colonna a cui si sta modificando la larghezza.
  • Larghezza di colonna, la larghezza desiderata della colonna.
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();

Impostazione della larghezza di tutte le colonne in un foglio di lavoro

Per impostare la stessa larghezza di colonna per tutte le colonne nel foglio di lavoro, utilizzare il metodo SetStandardWidth della raccolta di 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();