How to read and write excel file

后端 未结 22 3163
北荒
北荒 2020-11-22 04:49

I want to read and write an Excel file from Java with 3 columns and N rows, printing one string in each cell. Can anyone give me simple code snippet for this? Do I need to

22条回答
  •  忘掉有多难
    2020-11-22 05:14

    If column number are varing you can use this

    package com.org.tests;
    import org.apache.poi.xssf.usermodel.*;
    import java.io.FileInputStream;
    import java.io.IOException;
    
    public class ExcelSimpleTest 
    {   
        String path;
        public FileInputStream fis = null;
        private XSSFWorkbook workbook = null;
        private XSSFSheet sheet = null;
        private XSSFRow row   =null;
        private XSSFCell cell = null;
    
        public ExcelSimpleTest() throws IOException
        {
            path = System.getProperty("user.dir")+"\\resources\\Book1.xlsx";
            fis = new FileInputStream(path); 
            workbook = new XSSFWorkbook(fis);
            sheet = workbook.getSheetAt(0);
        }
        public void ExelWorks()
        {
            int index = workbook.getSheetIndex("Sheet1");
            sheet = workbook.getSheetAt(index);
            int rownumber=sheet.getLastRowNum()+1;  
    
            for (int i=1; i

    The corresponding mavendependency can be found here

提交回复
热议问题