尝试使用Apache POI打印xlsx内容

时间:2015-02-11 14:27:43

标签: java apache-poi xmlbeans

我想阅读.xlsx文件并显示内容。为此,我添加了这些库:

  • 的xmlbeans-2.6.0.jar
  • POI-3.11-20141221.jar
  • POI-例子-3.11-20141221.jar
  • POI-excelant-3.11-20141221.jar
  • POI-OOXML-3.11-20141221.jar
  • POI-OOXML-架构 - 3.11-20141221.jar
  • POI暂存器-3.11-20141221.jar

我收到此错误:

  

用法:BiffDrawingToXml [options] inputWorkbook选项:
  -exclude-workbook排除工作簿级别记录-sheet-indexes具有指定索引的输出表单-sheet-namek具有指定名称的输出表单

有人能告诉我发生了什么事吗?这是代码:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* @author giftsam
*/
public class Principal
{   
    public static void main(String[] args) throws IOException
    {       
        File myFile = new File("C://2feb15.xlsx");
        FileInputStream fis = new FileInputStream(myFile);

        // Finds the workbook instance for XLSX file
        XSSFWorkbook myWorkBook = new XSSFWorkbook (fis);

        // Return first sheet from the XLSX workbook
        XSSFSheet mySheet = myWorkBook.getSheetAt(0);

        // Get iterator to all the rows in current sheet
        Iterator<Row> rowIterator = mySheet.iterator();

        // Traversing over each row of XLSX file
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();

            // For each row, iterate through each columns
            Iterator<Cell> cellIterator = row.cellIterator();             

            while (cellIterator.hasNext()) {

                Cell cell = cellIterator.next();

                switch (cell.getCellType()) {
                case Cell.CELL_TYPE_STRING:
                    System.out.print(cell.getStringCellValue() + "\t");                 
                    break;
                case Cell.CELL_TYPE_NUMERIC:
                    System.out.print(cell.getNumericCellValue() + "\t");
                    break;
                case Cell.CELL_TYPE_BOOLEAN:
                    System.out.print(cell.getBooleanCellValue() + "\t");
                    break;
                default :

                }
            }
            System.out.println("");
        }   
    }   
}

0 个答案:

没有答案