Parsing Excel file without Apache POI

ぐ巨炮叔叔 提交于 2019-12-05 10:04:19

CSV is a text format, so it can be parsed using the delimiters. Old Excel is a binary and proprietary format so it needs clever decoding. The new Excel format is zipped XMLs, but one should also understand the structure of this document before it could be transformed into something as simple as reading cells one by one. So the answer to your question is no, you'll need to use Apache POI, and also - there's nothing wrong with that.

As a side note, on the path to become a good developer you will need to learn to do a bit of your own research before looking for help. Get your hands dirty is the best way to learn things.

You've probably confused what you've heard, or the person telling you was confused.

Some parts of Excel files can be stored (somewhat) as CSV files as the tabular data structure fits well within a CSV file format. However, if you save in CSV format then you just get plain text in each cell - you lose all formatting information, any graphs, multiple worksheets and so on.

The native XLS excel format is what Apache POI works with, and so can handle everything in excel, not just restrictive plain text in certain cells. CSV files have their uses but they're definitely not a straight replacement for normal Excel files.

i tried to read/write excel file without using any external JAR like POI or any other. I am able to write file as xls format. Here is my Code

FileWriter fwriter = new FileWriter(file,true);
writer = new BufferedWriter(fwriter);
writer.newLine();
writer.write("a"    + "\t");
writer.write("b"    + "\t");
writer.write("c"    + "\t");
writer.write("d"    + "\t");
writer.write("e"    + "\t");
writer.write("f"    + "\t");

Reading File here is my code for reading

if(file != null) {
            BufferedReader reader = null;
            try {
                reader = new BufferedReader(new FileReader(file));
                String line;
                while((line = reader.readLine()) != null) {
                    String[] component = line.split("\\t");
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if(reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
InputStream is = new FileInputStream(new File(filepath));
        StreamingReader reader=null;
        try {
            reader = StreamingReader.builder()
                    .rowCacheSize(100)     
                    .bufferSize(4096)     
                    .sheetIndex(0)        
                    .read(is);
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }finally{
            is.close();
        }
        //pass here to reader and itrate it 
          for (Row row : reader) {
            if (row.getRowNum()!=0){
                for (Cell cell : row) {
              // write ur logic to store ur value 
                }

            }
        }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!