行と列の自動調整

Aspose.Cells for Java を使用して行と列を自動調整する方法

行の幅と高さを自動調整する最も簡単な方法は、Worksheet.autoFitRow メソッドを呼び出すことです。 autoFitRow メソッドは、(サイズ変更される行の) 行インデックスをパラメータとして受け取ります。

**ご注意ください:**Java を使用して Excel スプレッドシートの行と列を自動調整する場合は、次のサイトにアクセスしてください。行と列の自動調整.

Java

 Workbook workbook = new Workbook("workbook.xls");

//Accessing the first worksheet in the Excel file

Worksheet worksheet = workbook.getWorksheets().get(0);

worksheet.autoFitRow(1); //Auto-fitting the 2nd row of the worksheet

worksheet.autoFitColumn(0); //Auto-fitting the 1st column of the worksheet

//Saving the modified Excel file in default (that is Excel 2003) format

workbook.save("AutoFit_Aspose.xls");

Apache POI SS - HSSF XSSF - 行と列の自動調整

Apache POI SS - HSSF および XSSF は列を自動調整するための Sheet.autoSizeColumn を提供します

Java

 InputStream inStream = new FileInputStream("workbook.xls");

Workbook workbook = WorkbookFactory.create(inStream);

Sheet sheet = workbook.createSheet("new sheet");

sheet.autoSizeColumn(0); //adjust width of the first column

sheet.autoSizeColumn(1); //adjust width of the second column

FileOutputStream fileOut;

fileOut = new FileOutputStream("AutoFit_Apache.xls");

workbook.write(fileOut);

fileOut.close();

実行コードをダウンロード

サンプルコードをダウンロード