我在Java项目中工作,我需要创建一个包含一些信息的xls文件.因此,根据信息量,我需要自动创建行和单元格以放置此信息.
示例:如果输入文档有13个站点信息,我需要创建13行,包含4个单元格.我是怎么做到的?..我的代码尝试:
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("new sheet");
int numberrows = Integer.parseInt(JOptionPane.showInputDialog(null, "numbers of sites??"));
String siteName = JOptionPane.showInputDialog(null, "Site name");
String rncname = JOptionPane.showInputDialog(null, "RncName");
for (int i = 0; i < numberrows; i++) {
HSSFRow linha = (HSSFRow) sheet.createRow(i);
linha.createCell((short) i ).setCellValue(siteName);
linha.createCell((short) i ).setCellValue(rncname);
}
Run Code Online (Sandbox Code Playgroud)
提前致谢..