usermodel可以从多个模块poi,poi.examples访问

时间:2018-04-11 21:05:07

标签: apache jar apache-poi

我在第9,11,13,15行遇到错误 - 包org.apache.poi.hssf.usermodel可从多个模块poi,poi.examples访问。我下载了最新的poi jar并将它们添加到模块路径中。请告诉我哪里出错了?

package apachetests;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.apache.poi.ss.usermodel.Row;

import org.apache.poi.ss.usermodel.Sheet;

import org.apache.poi.ss.usermodel.Workbook;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class Writetoexcel {

    public static void main(String []args){

        try {

            // Specify the file path which you want to create or write

            File src=new File("C:\\Users\\Venkat\\Desktop\\Hima2017\\Names.xlsx");

            // Load the file

            FileInputStream fis=new FileInputStream(src);

            // load the workbook

            XSSFWorkbook wb=new XSSFWorkbook(fis);

            // get the sheet which you want to modify or create

            XSSFSheet sh1= wb.getSheetAt(0);

            // getRow specify which row we want to read and getCell which column

            System.out.println(sh1.getRow(0).getCell(0).getStringCellValue());

            System.out.println(sh1.getRow(0).getCell(1).getStringCellValue());

            System.out.println(sh1.getRow(1).getCell(0).getStringCellValue());

            System.out.println(sh1.getRow(1).getCell(1).getStringCellValue());

            System.out.println(sh1.getRow(2).getCell(0).getStringCellValue());

            System.out.println(sh1.getRow(2).getCell(1).getStringCellValue());

            // here createCell will create column

            // and setCellvalue will set the value

            sh1.getRow(0).createCell(2).setCellValue("2.41.0");

            sh1.getRow(1).createCell(2).setCellValue("2.5");

            sh1.getRow(2).createCell(2).setCellValue("2.39");


            // here we need to specify where you want to save file

            FileOutputStream fout=new FileOutputStream(new File("location of file/filename.xlsx"));


            // finally write content

            wb.write(fout);

            // close the file

            fout.close();

        } catch (Exception e) {

            System.out.println(e.getMessage());

        }

    }

}

谢谢, 希马

1 个答案:

答案 0 :(得分:0)

最新版本已解决此问题。

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.0</version>
        </dependency>