2016-07-23 6 views
0

enter image description hereは、私がどのようにマッパーを進める方法を教えいずれかをxml.Canするために、Excelを変換したい

をXMLにExcelを変換したいですか?私のコード :

public class WorkGroupReader implements ItemReader<List<String>> { 
    WorkGroupMapper linemapper; 

    public void setLinemapper(WorkGroupMapper linemapper) { 
     this.linemapper = linemapper; 
    } 

    @Override 
    public List<String> read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException,BiffException, IOException { 
      String FilePath = "E:\\ide-workspaces\\OmniFeed\\input\\WorkGroup.xls"; 
      FileInputStream fs = new FileInputStream(FilePath); 
      Workbook wb = Workbook.getWorkbook(fs); 

      // TO get the access to the sheet 
      Sheet sh = wb.getSheet("WorkGroup"); 

      // To get the number of rows present in sheet 
      int totalNoOfRows = sh.getRows(); 

      // To get the number of columns present in sheet 
      int totalNoOfCols = sh.getColumns(); 

      List<String> list=new ArrayList<String>(); 
      for (int row = 1; row < totalNoOfRows; row++) { 

       for (int col = 1; col < totalNoOfCols; col++) { 
        //System.out.print(sh.getCell(col, row).getContents() + "\t"); 
        list.add(sh.getCell(col, row).getContents()); 
        //return linemapper.mapLine(sh.getCell(col, row).getContents(), 0); 
       } 
      } 

      return list; 

私は読者にマッピングする方法を理解していませんか?

+0

を使用してサンプルコードです。 –

+0

あなたの質問はまだ広すぎます。 XMLとしてデータを書き出す方法を知りたければ、Java/XMLに関するチュートリアルがたくさんあります。 Googleにお尋ねください。もしあなたが私たちにあなたのためにそれを書こうとしているのであれば....申し訳ありませんが、これは無料のコーディングサービスではありません。 –

+0

また、そのような画像へのリンクはぼやけて見えます。あなたは質問自体のテキストとして、そのイメージにあるものを表現することができます。 –

答えて

0

あなたは.XLSを読んだり、Mavenのプロジェクトでは
を.xlsxのようにApache POIライブラリを使用することができます。プロジェクトのPOMに次の依存関係を追加します。 .xmlファイル:

<!--For Excel 2003 format only (HSSF) --> 
<dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi</artifactId> 
    <version>2.6.12</version> 
</dependency> 

<!--For Excel 2007 format (XSSF) --> 
<dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi-ooxml</artifactId> 
    <version>3.14</version> 
</dependency> 


ここでは、画像を表示now.please返信してくださいXSSF


    import java.io.File; 
    import java.io.FileInputStream; 
    import java.io.IOException; 
    import org.apache.poi.ss.usermodel.Cell; 
    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.util.IOUtils; 
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelToXml { public static void main(String[] args) { File excelFile = new File(args[0]); if (excelFile.exists()) { Workbook workbook = null; FileInputStream inputStream = null; try { inputStream = new FileInputStream(excelFile); workbook = new XSSFWorkbook(inputStream); Sheet sheet = workbook.getSheetAt(0); for (Row row : sheet) { for (Cell cell : row) { switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: System.out.print(cell.getStringCellValue()); break; case Cell.CELL_TYPE_BOOLEAN: System.out.print(cell.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: System.out.print(cell.getNumericCellValue()); break; } System.out.print("\t"); } System.out.println(); } } catch (IOException e) { // handle the exception } finally { IOUtils.closeQuietly(workbook); IOUtils.closeQuietly(inputStream); } } } }
0

読者とのマッピング方法が分かりませんか?

あなたはリーダーとマップしません。

/をメモリ内のデータ構造として読み込み、データ構造をXMLとして書き出します。それがあなたがここでやろうとしているものだと仮定します。

(あなたはまた、インクリメンタルにそれを行うが、物事を複雑にしないことができますでした。)

関連する問題