다음 코드를 살펴보십시오. 난 CSV 파일에 데이터를 쓰고 싶지 않아 JExcel API
Excel 데이터를 CSV로 가져 오기
import java.io.*;
import jxl.*;
import java.util.*;
class ConvertCSV
{
public static void main(String[] args)
{
try
{
//File to store data in form of CSV
File f = new File("input.csv");
OutputStream os = (OutputStream)new FileOutputStream(f);
String encoding = "UTF8";
OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
BufferedWriter bw = new BufferedWriter(osw);
//Excel document to be imported
String filename = "C:/Users/yohan/Documents/NetBeansProjects/ExcelTest/input.xlsx";
WorkbookSettings ws = new WorkbookSettings();
ws.setLocale(new Locale("en", "EN"));
Workbook w = Workbook.getWorkbook(new File(filename),ws);
// Gets the sheets from workbook
for (int sheet = 0; sheet < w.getNumberOfSheets(); sheet++)
{
Sheet s = w.getSheet(sheet);
bw.write(s.getName());
bw.newLine();
Cell[] row = null;
// Gets the cells from sheet
for (int i = 0 ; i < s.getRows() ; i++)
{
row = s.getRow(i);
if (row.length > 0)
{
bw.write(row[0].getContents());
for (int j = 1; j < row.length; j++)
{
bw.write(',');
bw.write(row[j].getContents());
}
}
bw.newLine();
}
}
bw.flush();
bw.close();
}
catch (UnsupportedEncodingException e)
{
System.err.println(e.toString());
}
catch (IOException e)
{
System.err.println(e.toString());
}
catch (Exception e)
{
System.err.println(e.toString());
}
}
}
를 사용하고,하지만 난 MUST은 StringBuffer를에로드 '필드'라는 "filedsBuffer"과 StringBuffer를에 부하 데이터로 "의 DataBuffer를"라는 쉼표로 구분 된 값.
그러나이 프로그램을 실행하면 다음과 같은 예외가 발생합니다.
jxl.read.biff.BiffException: Unable to recognize OLE stream
어떻게 해결할 수 있습니까? 이 API로이 작업을 수행 할 수 없으면 다른 API를 사용하여 답변하십시오. 도와주세요
파일 확장자를 .xlsx가 아닌 .xls로 변경하여 테스트 해 보겠습니까? 그것은 당신을 도울 수 있습니다. –
jxl이 xlsx 형식을 지원합니까? jxl이 xlsx가 아닌 이전 형식을 지원할 것을 제안하는 많은 질문과 대답이 있습니까? – Jayan
@Jayan : 가능합니다. 그렇다면 ... 가능하면 다른 API를 요청하여 업데이트했습니다. –