hi
how to load data from two or more csv to excel using LightCellDataProvider Api.
please find the attached code file and input file.
how to open a csv file from LightCell Dataprovider Implemented class.
please give the solution to this.
Thanks & regards
Ranjith.
Hi Ranjith,
Thank you for providing your source code and data file. We will be looking into it very soon and provide you all assistance you may require.
hi
any update on this?
Thanks & Regards
Ranjith kumar
Hi,
The performance(memory) issue of using LightCellsDataProvider
LightCellsDataProvider is mainly designed for saving a workbook whose cells data is got from other datasource, especially when the cells data can be fetched one by one in stream mode. Such as when you can get cell data one by one from ResultSet, InputStream, and so on. If the datasource is large and you have to load it into memory completely before using it, the data set itself will need lots of memory too. From your code, you build one complete Workbook structure by loading all data from CSV file first. If the csv file is large, then your read Workbook object will cost lots of memory and may cause performance issue before you use LightCellsDataProvider to create the resultant excel file. This way does not fully take the advantage of LightCellsDataProvider. To solve your performance issue, we think you need a way to load the data from csv in stream mode and create the resultant excel file by LightCellsDataProvider APIs at the same time. Such as you can parse the CSV file by yourself, line by line. Or, we may provide you some solutions like LightCells to read the CSV in stream mode if you need. But we need more time to implement such solution and please confirm us it can fit your requirement before we start to work for it.
Load data from 2 or more csv file and save workbook by LightCellsDataProvider
It is in the same way as you load data from one csv file. Such as, if you need to combine two csv file into one workbook, you can keep the row index in your implementation of LightCellsDataProvider. When the first csv file has finished, you can continue to increase the row index for data read from the second csv file. Thus the data of second csv file will be appended into the same sheet just after the last row of first csv file.
JAVA Code Sample:
public class Impl implements LightCellsDataProvider
{
private String[] rowValues;
private int rowIndex = 0;
private short colIndex;
private BufferedReader brCSV1;
private BufferedReader brCSV2;
...
public int nextRow()
{
if(brCSV1 != null)
{
String data = brCSV1.readLine();
if(data == null)
{
brCSV1 = null;
return -1;
}
rowValues = parseRow(data);
colIndex = 0;
return rowIndex++;
}
else if(brCSV2 != null)
{
String data = brCSV2.readLine();
if(data == null)
{
brCSV2 = null;
return -1;
}
rowValues = parseRow(data);
colIndex = 0;
return rowIndex++;
}
else
{
return -1;
}
}
public short nextCell()
{
if(colIndex < rowValues.length)
{
return colIndex++;
}
return -1;
}
public void startCell(Cell cell)
{
cell.setValue(rowValues[colIndex-1]);
...
}
...
}
As we said, the performance issue may exist if you csv files are large and you use the way of loading all csv files first by Workbook model. If you can read the csv file in stream mode, we are sure lots of memory will be saved. For xlsx file format, there should not have such memory issue any more.