Justera radhöjd och kolumnbredd
Arbeta med rader
Justering av radhöjd
Aspose.Cells tillhandahåller en klass,Arbetsbok , som representerar en Microsoft Excel-fil. DeArbetsbok klass innehåller enArbetsbladssamlingsom ger åtkomst till varje kalkylblad i Excel-filen. Ett arbetsblad representeras avArbetsblad klass. DeArbetsblad klass ger enCellssamling som representerar alla celler i kalkylbladet.
DeCellssamling 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 radhöjden
Det är möjligt att ställa in höjden på en enstaka rad genom att anropaCells samlingenssetRowHeight metod. DesetRowHeight metod tar följande parametrar:
- 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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingHeightOfRow.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the height of the second row to 13 | |
cells.setRowHeight(1, 13); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingHeightOfRow_out.xls"); |
Ställa in höjden på alla rader
För att ställa in samma radhöjd för alla rader i ett kalkylblad, användCells samlingenssetStandardHeightmetod.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingHeightAllRows.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the height of all rows in the worksheet to 15 | |
worksheet.getCells().setStandardHeight(15f); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingHeightAllRows_out.xls"); |
Arbeta med kolumner
Ställa in bredden på en kolumn
Ställ in bredden på en kolumn genom att anropaCells samlingenssetColumnWidth metod. DesetColumnWidth metod 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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingWidthOfColumn.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the width of the second column to 17.5 | |
cells.setColumnWidth(1, 17.5); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingWidthOfColumn_out.xls"); |
Ställa in bredden på alla kolumner
För att ställa in samma kolumnbredd för alla kolumner i ett kalkylblad, användCells samlingenssetStandardWidthmetod.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingWidthOfAllColumns.class) + "rows_cloumns/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Cells cells = worksheet.getCells(); | |
// Setting the width of all columns in the worksheet to 20.5 | |
worksheet.getCells().setStandardWidth(20.5f); | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.save(dataDir + "SettingWidthOfAllColumns_out.xls"); |