Ajuster la hauteur de la ligne et la largeur de la colonne
Travailler avec des lignes
Ajuster la hauteur de la ligne
Aspose.Cells fournit une classe, Workbook qui représente un fichier Microsoft Excel. La classe Workbook contient une WorksheetCollection qui permet d’accéder à chaque feuille de calcul du fichier Excel. Une feuille de calcul est représentée par la classe Worksheet. La classe Worksheet fournit une collection Cells qui représente toutes les cellules de la feuille de calcul. La collection Cells propose plusieurs méthodes pour gérer les lignes ou les colonnes dans une feuille de calcul. Certaines d’entre elles sont discutées ci-dessous en détail.
Définir la hauteur d’une ligne
Il est possible de définir la hauteur d’une seule ligne en appelant la méthode SetRowHeight de la collection Cells. La méthode SetRowHeight prend les paramètres suivants comme suit :
- Index de ligne, l’index de la ligne pour laquelle vous modifiez la hauteur.
- Hauteur de la ligne, la hauteur de la ligne à appliquer sur la ligne.
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(); |
Définir la hauteur de toutes les lignes dans une feuille de calcul
Si les développeurs ont besoin de définir la même hauteur de ligne pour toutes les lignes dans la feuille de calcul, ils peuvent le faire en utilisant la méthode SetStandardHeight de la collection 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(); |
Travailler avec les colonnes
Définir la largeur d’une colonne
Définissez la largeur d’une colonne en appelant la méthode SetColumnWidth de la collection Cells. La méthode SetColumnWidth prend les paramètres suivants :
- Index de la colonne, l’index de la colonne dont vous changez la largeur.
- Largeur de colonne, la largeur de colonne souhaitée.
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(); |
Réglage de la largeur de toutes les colonnes dans une feuille de calcul
Pour définir la même largeur de colonne pour toutes les colonnes dans la feuille de calcul, utilisez la méthode SetStandardWidth de la collection 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(); |