|
-
July 18th, 2017, 05:51 AM
#1
How to insert openoffice spread sheet data into database instead of printing on conso
Below is my code which reads the open office spread sheet data nad displays it on the console but i need to insert into database nstead of printing on console.can any on help me out as i am new to this.I had used jopendocument 1.3 api for reading the open office spread sheet data
Code:
public void readODS(File file)
{
Sheet sheet;
try {
//Getting the 0th sheet for manipulation| pass sheet name as string
sheet = SpreadSheet.createFromFile(file).getSheet(0);
//Get row count and column count
int nColCount = sheet.getColumnCount();
int nRowCount = sheet.getRowCount();
System.out.println("Rows :"+nRowCount);
System.out.println("Cols :"+nColCount);
//Iterating through each row of the selected sheet
MutableCell cell = null;
for(int nRowIndex = 0; nRowIndex < nRowCount; nRowIndex++)
{
//Iterating through each column
int nColIndex = 0;
for( ;nColIndex < nColCount; nColIndex++)
{
if (nColIndex==14 && cell.isEmpty())
{
throw new RuntimeException(String.format("Cell at col=%d,row=%d is empty%n", nColIndex, nRowIndex));
}
cell = sheet.getCellAt(nColIndex, nRowIndex);
System.out.print(cell.getValue()+ " ");
}
System.out.println();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
Last edited by 2kaud; July 18th, 2017 at 09:18 AM.
Reason: Added code tags
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|