Number Stored as Text in Excel created using DynamicReports - java

I am using Dynamic Reports to create Reports and am able to create it. But the issue is that when i convert it to excel, the cell in the excel showing a warning as Number Stored as Text. Because of this no operation is possible.
Here is my code
File file = new File("c:/report.xls");
JasperXlsExporterBuilder xlsExporter = export.xlsExporter(file).setDetectCellType(true).setIgnorePageMargins(true)
.setWhitePageBackground(false).setRemoveEmptySpaceBetweenColumns(true);
report.addProperty(JasperProperty.EXPORT_XLS_FREEZE_ROW, "2").ignorePageWidth().ignorePagination().toXls(xlsExporter);
How to remove this error.

Add the following line to your code:
<property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
Source
EDIT
In the Dynamic Reports samples, the report variable also sets the following. This could help depending on the column.
.columns(
itemColumn,
col.column("Quantity", "quantity", type.integerType()),
col.column("Unit price", "unitprice", type.bigDecimalType()))

Related

Anylogic import new Excel file for each iteration of a simulation experiment

In my anylogic model my agents receive their parameters from a database table, which is based on an Excel file. In the Excel file, each cell has its own code stored, so each time I open the file, the cell values change.
I would like to have that with each automatic run of my model the Excel file is read in again as the database table (i.e. the parameter values of the agents change).
In the "Parameter Variation Experiment" I entered this code under "after iteration":
String tempString = excelFile_DatabasisLinks.getCellStringValue(1, rowCounter, 1);
ModelDatabase modelDB = getEngine().getModelDatabase();
Database myNewFile = new Database(this, "rohdaten2", tempString);
modelDB.importFromExternalDB(myNewFile.getConnection(), "Rohdaten", "rohdaten", true, false);
rowCounter += 1;
I have the code form this anylogic help page. Using a variable to be able to change the path of the file (i.e. the file) seems to work (anylogic doesn't throw an error).
In the currently used dummy model, the agents receive their parameters at the source.
At the sink, the parameter values are written via collections into another excel (results) file.
I put obvious pattern into my data files, to see if the data changes, but I always receive the same excel file in my results file.
I read that anylogic copies the excel tables to its temporary files to make simulation runs faster. I hoped the code above would be a workaround, but it is not.
I'm grateful for any suggestions how to make this work!
I could not find out what is wrong with the above code or how to get it work.
However, I found a workaround using the "excelFile "-Block.
In the main agent (the agent where all other agents live) in the agent actions in "on startup":
excelFile.readFile();
ensures that the excel file is updated before each run. The parameters are added via
agent.set_<parametername>(excelFile.getCellBooleanValue( sheet number, row number, column number)
"on exit" in the source.
I hope this helps everyone with a similar problem.

How to keep zero begin string when export data using opencsv library

I using opencsv library in java and export csv. But i have problem. When i used string begin zero look like : 0123456 , when i export it remove 0 and my csv look like : 123456. Zero is missing. I using way :
"\"\t"+"0123456"+ "\""; but when csv export it look like : "0123456" . I don't want it. I want 0123456. I don't want edit from excel because some end user don't know how to edit. How to export csv using open csv and keep 0 begin string. Please help
I think it is not really the problem when generating CSV but the way excel treats the data when opened via explorer.
Tried this code, and viewed the CSV in a text editor ( not excel ), notice that it shows up correctly, though when opened in excel, leading 0s are lost !
CSVWriter writer = new CSVWriter(new FileWriter("yourfile.csv"));
// feed in your array (or convert your data to an array)
String[] entries = "0123131#21212#021213".split("#");
List<String[]> a = new ArrayList<>();
a.add(entries);
//don't apply quotes
writer.writeAll(a,false);
writer.close();
If you are really sure that you want to see the leading 0s for numeric values when excel is opened by user, then each cell entry be in format ="dataHere" format; see code below:
CSVWriter writer = new CSVWriter(new FileWriter("yourfile.csv"));
// feed in your array (or convert your data to an array)
String[] entries = "=\"0123131\"#=\"21212\"#=\"021213\"".split("#");
List<String[]> a = new ArrayList<>();
a.add(entries);
writer.writeAll(a);
writer.close();
This is how now excel shows when opening excel from windows explorer ( double clicking ):
But now, if we see the CSV in a text editor, with the modified data to "suit" excel viewing, it shows as :
Also see link :
format-number-as-text-in-csv-when-open-in-both-excel-and-notepad
have you tried to use String like this "'"+"0123456". ' char will mark number as text when parse into excel
For me OpenCsv works correctly ( vers. 5.6 ).
for example my csv file has a row as the following extract:
"999739059";;;"abcdefgh";"001024";
and opencsv reads the field "1024" as 001024 corretly. Of course I have mapped the field in a string, not in a Double.
But, if you still have problems, you can grab a simple yet powerful parser that fully adheres with RFC 4180 standard:
mykong.com
Mykong shows you some examples using opencsv directly and, in the end, he writes a simple parser to use if you don't want to import OpenCSV , and the parser works very well , and you can use it if you still have any problems.
So you have an easy-to-understand source code of a simple parser that you can modify as you want if you still have any problem or if you want to customize it for your needs.

Read Excel file using Java with Property file

I am trying to read an Excel file using Java.
I did this successfully by using org.apache.poi which is returning all of the data column wise.
But now I want to read the same excel file by column names only which will be given by the user. The twisting part is that I want to accept column names from a property file and only those names, which are in the property file, those column's data should be shown by the program. So any suggestions? How do I do it?
use net.sf.supercsv library for reading EXL file by header/column name

birt merge cells together when exporting to excel

I'm facing a problem with birt report , in the first column i have an image to display , when exporting to excel i see that there is a lot of merged cell together : see the picture below
NB:when exporting to excel i'm using an emitter
options = new EXCELRenderOption();
options.setOutputFormat("xls");
options.setOption(IRenderOption.EMITTER_ID, "org.eclipse.birt.report.engine.emitter.nativexls");
any help how to fix this please?

Pivot table refresh and save code in aspose cells for java corrupts excel file

I am using aspose-cells-8.7.2-java. When I refresh the pivot table and save it, the excel file is getting corrupted. When I try to open the excel file I am getting the alert message as below :
"Excel found unreadable content in 'Book1.xlsx'.Do you want to recover the contents of this workbook?If you trust the source file of this workbook, click yes."
The code is as below :
Workbook wb = new Workbook("Book1.xlsx");
PivotTable pt = wb.getWorksheets().get(1).getPivotTables().get(0);
pt.refreshData();
pt.calculateData();
wb.save("Book1.xlsx");
Any help ?
I found this thread where the same issue is logged as a ticket :
http://www.aspose.com/community/forums/thread/683715/aspose.cells-generates-a-corrupted-xlsx-file-excel-2007-fails-to-open.aspx.
Is this issue solved?
I'm afraid the logged issue is not resolved yet. By the way, do you use similar Excel file or yours template file "Book1.xlsx" is different. Moreover, your issue can be template specific (if you are using different file) and might have different scenarios, so we need your template "Book1.xlsx" file to properly evaluate your issue on our end. We recommend you to kindly create a separate thread in Aspose.Cells forum with your template Excel file, we will evaluate your issue and help you better there.
I am working as Support developer/ Evangelist at Aspose.

Categories

Resources