I’m trying to run Cells.importResultSet method. I used an existing excel template file.
It’s working, but the formatting of my first row are not being applied to another rows…
This is my code:
final ImportTableOptions ITO = new ImportTableOptions();
ITO.setFieldNameShown(Boolean.FALSE);
workbook.getWorksheets().get(“Plan 1”).getCells().importResultSet(rs, “A2”, ITO);
See the attached picture
firstline.jpg (35.7 KB)
@vagastec,
Thanks for providing us sample code segment, screenshot and details.
Please change the lines of code as following:
e.g
Sample code:
final ImportTableOptions ITO = new ImportTableOptions();
ITO.setFieldNameShown(Boolean.FALSE);
ITO.setInsertRows(Boolean.TRUE);
workbook.getWorksheets().get(“Plan 1”).getCells().importResultSet(rs, “A2”, ITO);
Let us know if you still find the issue.
Hello Amjad.
I changed my code, but the problem continue.
I’m attaching my file. You can see it doesn’t inserting rows…
ASPOSE.zip (8.1 KB)
I’m using Aspose Cells 18.1 jar
@vagastec,
Thanks for the sample file.
Yes, I noticed this issue but you may easily cope with it by using Cells.InsertRows() to add empty rows = number of records -1. See the sample code segment for your reference:
e.g
Sample code:
...............
// Create SQL Statement with Connection object
java.sql.Statement st = conn.createStatement(rs.TYPE_SCROLL_INSENSITIVE, rs.CONCUR_READ_ONLY);
// Execute SQL Query and obtain ResultSet
rs = st.executeQuery("SELECT Field1, Field2 FROM Table1");
int rowCount = 0;
while(rs.next()){
rowCount++;
}
System.out.println(rowCount);
rs.beforeFirst();
// Create workbook object
Workbook wb = new Workbook("f:\\files\\Book1.xlsx");
// Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
// Access cells collection
Cells cells = ws.getCells();
// Create import table options
ImportTableOptions options = new ImportTableOptions();
options.setInsertRows(true);
options.setFieldNameShown(false);
cells.insertRows(1,rowCount-1);
// Import Result Set
cells.importResultSet(rs, 1, 0, options);
Hope, this helps a bit.
I did the way you indicated me and now it worked.
Thank you!
@vagastec,
Good to know that the workaround figures out your issue now.
Moreover, as we have already observed the issue by testing the scenario/case. We found that by setting the ImportTableOptions.setInsertRows() option to true is not working while importing the ResultSet to worksheet. The option does not insert blank rows, hence the formatting of the rows won’t be copied. A ticket with an id “CELLSJAVA-42514” is logged into our database. We will look into it to try to figure it out soon.
Once we have an update on it, we will let you know here.
Nice that you are including it to fix the bug!
Thanks!
@vagastec
Thanks for using Aspose APIs.
Please download and try the following fix and let us know your feedback.
Please also set the correct value for ImportTableOptions.TotalRows property before importing the result.
The issues you have found earlier (filed as CELLSJAVA-42514) have been fixed in this Aspose.Cells for Java 18.3 update. Please also check the <a href="Installation|Documentation
The issues you have found earlier (filed as CELLSJAVA-42514) have been fixed in this Aspose.Cells for Java 18.3 update. Please also check the document for your reference: Installation|Documentation