We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Using LightCellsDataHandler for CSV

Hello team,

LightCellsDataHandler works like charm for excel files.

While trying with CSV files, it does NOT seem to be working.

Can someone provide the code sample to open a CSV file through LightCellsDataHandler.

Currently, I am using the following code to open a CSV through LightCellsDataHandler, and it is NOT working:

ReadCSVThroughAspose.java:

import com.aspose.cells.FileFormatType;
import com.aspose.cells.LightCellsDataHandler;
import com.aspose.cells.LoadDataFilterOptions;
import com.aspose.cells.LoadFilter;
import com.aspose.cells.LoadOptions;
import com.aspose.cells.TxtLoadOptions;
import com.aspose.cells.Workbook;

public class ReadCSVThroughAspose {
public static void main(String[] args) throws Exception {
String fileName = “abc.csv”;
LightCellsDataHandler handler = new CSVHandler();

// TxtLoadOptions options = new TxtLoadOptions();
// options.setMultiEncoded(true);
// options.setLightCellsDataHandler(handler);
// options.setLoadFilter(new LoadFilter(LoadDataFilterOptions.ALL & ~LoadDataFilterOptions.CELL_BLANK));


LoadOptions loadOptions = new LoadOptions(FileFormatType.CSV);
loadOptions.setLightCellsDataHandler(handler);
loadOptions.setLoadFilter(new LoadFilter(LoadDataFilterOptions.ALL & ~LoadDataFilterOptions.CELL_BLANK));

new Workbook(fileName, loadOptions);

System.out.println(“completed.”);
}
}

CSVHandler.java:

import com.aspose.cells.Cell;
import com.aspose.cells.LightCellsDataHandler;
import com.aspose.cells.Row;
import com.aspose.cells.Worksheet;

public class CSVHandler implements LightCellsDataHandler {

@Override
public boolean processCell(Cell arg0) {
// TODO Auto-generated method stub
return true;
}

@Override
public boolean processRow(Row row) {
System.out.println("processing row: " + row.getIndex());
return true;
}

@Override
public boolean startCell(int arg0) {
// TODO Auto-generated method stub
return true;
}

@Override
public boolean startRow(int rowIndex) {
System.out.println("startRow rowIndex: " + rowIndex);
return true;
}

@Override
public boolean startSheet(Worksheet ws) {
System.out.println(ws.getName());
return true;
}

}

Output:
completed.

Hi,


I am afraid, Aspose.Cells’ LightCells API only works for XLS and XLSX file formats. I think you should use normal APIs (mode) to load the CSV file and retrieve the values. If you find any issue regarding performance, we will check it soon.

Thank you.