⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csvdatasource.java

📁 利用jasperreports和Ireport做报表2
💻 JAVA
字号:
package net.ensode.jasperbook;import java.io.FileNotFoundException;import java.io.IOException;import java.io.Reader;import java.util.List;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRField;import net.sf.jasperreports.engine.JRRewindableDataSource;import au.com.bytecode.opencsv.CSVReader;public class CsvDataSource implements JRRewindableDataSource{  private CSVReader csvReader;  private List rows;  private int currentRowIndex = -1;  private int currentColIndex = 0;  private int totalRows;  public CsvDataSource(Reader reader)  {    try    {      csvReader = new CSVReader(reader);      rows = csvReader.readAll();      totalRows = rows.size();    }    catch (FileNotFoundException e)    {      e.printStackTrace();    }    catch (IOException e)    {      e.printStackTrace();    }  }  public boolean next() throws JRException  {    boolean retVal = true;    currentRowIndex++;    currentColIndex = 0;    if (currentRowIndex >= totalRows)    {      retVal = false;    }    return retVal;  }  public Object getFieldValue(JRField arg0) throws JRException  {    String value = null;    String[] currentRow = (String[]) rows.get(currentRowIndex);    value = currentRow[currentColIndex];    currentColIndex++;    return value;  }  public void moveFirst() throws JRException  {    currentRowIndex = 0;    currentColIndex = 0;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -