乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>java</em> poi怎么<em>获取Excel</em>

<em>java</em> poi怎么<em>获取Excel</em>

作者:乔山办公网日期:

返回目录:excel表格制作


.计数器定义在e799bee5baa6e997aee7ad94e58685e5aeb9362 循环读取sheet的 循环里面不就好了么....

public static void main(String[] args) throws Exception {
    FileInputStream fileInputStream = new FileInputStream("path");
    Workbook workbook = new HSSFWorkbook(fileInputStream); //读取excel
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        Sheet sheet = workbook.getSheetAt(i);//获取sheet
        int count = 0; //总条数  第二个sheet自动归0
        for (int j = 0; j < sheet.getPhysicalNumberOfRows(); j++) {
            Row row = sheet.getRow(j); // 获取行
            // count++; //按行的话
            for (int k = 0; k < row.getPhysicalNumberOfCells(); k++) {
                Cell cell = row.getCell(k); //获取单元格
                // count ++ ; 按单元格的话
            }
        }
    }
}


java poi获取Excel sheet页的数量方法如下:

在导出excel时候需要导出多个sheet页,后面sheet页会覆盖前面sheet页的内容。
这么写代码:
HSSFWorkbook workbook = null;
workbook=new HSSFWorkbook();

for(){

//没有现成的文件需要重新计算
HSSFSheet sheet_sin =workbook.createSheet(month_query1);
sheet_sin= makeJDL(year_query,month_query1,sheet_sin,workbook);

}


WritableWorkbook workBook = null;
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/vnd.ms-excel");
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
String excelName = "yuyueliebiao" + format.format(new Date());
response.setHeader("Content-Disposition", "attachment; filename=\"" + excelName + ".xls\"");
response.setHeader("Cache-Control", "private");
response.setHeader("Pragma", "");
workBook = Workbook.createWorkbook(response.getOutputStream());
WritableSheet sheet = workBook.createSheet("sheet", 0);
Label label;
for (int i = 0; i < infs.size(); i++) {
HashMap inf = (HashMap) infs.get(i);
int j = 0;
label = new Label(j++, i, (String) inf.get("djlx"));
sheet.addCell(label);
label = new Label(j++, i, (String) inf.get("zch"));
sheet.addCell(label);
label = new Label(j++, i, (String) inf.get("qylx"));
sheet.addCell(label);
label = new Label(j++, i, (String) inf.get("qymc"));
sheet.addCell(label);
label = new Label(j++, i, (String) inf.get("yyrq"));
sheet.addCell(label);
label = new Label(j++, i, (String) inf.get("sqr"));
sheet.addCell(label);
label = new Label(j++, i, (String) inf.get("djjg"));
sheet.addCell(label);

}
workBook.write();
response.getOutputStream().flush();
response.getOutputStream().close();

获取Excel中的sheet页数量和名zhidao额如下

int coloumNum=sheet.getRow(0).getPhysicalNumberOfCells();//获得总列数

int rowNum=sheet.getLastRowNum();//获得总行数

就可以

相关阅读

  • <em>Excel</em> 如何实现点击<em>sheet</em>1

  • 乔山办公网excel表格制作
  • 1、选择sheet1中的某个单元格2、鼠标右键-超链接3、在插入超链接中的链接到内,选择本文档中的位置然后选择sheet24、在“请键入单元格引用”中输入某一列,如“A1:A10”5、回车EXCEL表中
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网