How to remove Spire.XLS signature from pdf File? - java

I'm working on java, i have an excel file named "file.xlsx" that i want to convert to pdf using Spire.XLS , this is the code i wrote for that :
//Create a Workbook instance
workbook = new Workbook();
//Load an Excel file
workbook.loadFromFile("file.xlsx");
//Get the first worksheet
sheet = workbook.getWorksheets().get(0);
//Add a new worksheet to the workbook
sheet_copy = workbook.getWorksheets().add("Copy of sheet1");
//Copy the first worksheet to the new worksheet
sheet_copy.copyFrom(sheet);
//Save the result file
workbook.saveToFile("file.xlsx");
workbook.saveToFile("result.pdf", com.spire.xls.FileFormat.PDF);
The pdf file is generated but with a signature : Evaluation Warning : The document was created with Spire.XLS for Java , i'm wondering about how to remove it , any idea ?

Either Request a pro Trial License OR
Per the age old answer use the free version
Free version doesn't have evaluation warning on result file.
Please make sure the version you were using is correct,
https://www.e-iceblue.com/forum/evaluation-warning-the-document-was-created-with-spire-pdf-t4925.html
https://www.e-iceblue.com/Download/xls-for-java-free.html
or for .net users
https://www.e-iceblue.com/Download/download-excel-for-net-free.html

Related

Selenium - store web element id in a spreadsheet, call the id from the spreadsheet in test?

So I'm trying to store a web element such as id in an excel spreadsheet, I then want to call the id from the sheet and place it in a test.
Would this work? The theory is then that others with less tech knowledge can modify tests within my workplace without editing code.
I am using the following code to read from the spreadsheet and place the cell data into a string.
File src=new File("C:\\Users\\Admin\\Documents\\ExcelData\\TestData.xlsx");
FileInputStream fis=new FileInputStream(src);
XSSFWorkbook wb=new XSSFWorkbook(fis);
XSSFSheet sheet1=wb.getSheetAt(0);
String data0=sheet1.getRow(0).getCell(0).getStringCellValue();
The difficulty I am having is when testing for example.
driver.findElement(By.name("q")).sendKeys("Java");
if I replace this with
driver.findElement(By.name(data0).sendKeys("Java");
this will not work.
Yes, you can get the input data from the external sheet as you asked.
This can be done using Apache POI Jars support.
Hope you are coding in Java.
The below link gives you enough code to your requirement. ->
Apache POI Examples
Code to read the data from Excel.
File file= new File(PATH);
FileInputStream inputStream = new FileInputStream(file);
Workbook workbook =new XSSFWorkbook(inputStream);
Sheet sheet = workbook.getSheet(SHEETNAME);
String[][] number=new String[10][10]; // temp array
for(int i=0;i<rowCount+1;i++)
{
Row row=s.getRow(i);
for(int j=0;j<=row.getLastCellNum();j++)
{
number[i][j]= row.getCell(j).toString(); // works only for cells of string type
}
}
Then you fetch data from number array.

POI 3.2 Excel file Data has been lost

I'm generating an Excel file in Java with POI 3.2 (Latest version I can use for my client).
Here is my code. As you can see I'm using HSSF because I need to make a XLS file.
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Reporting");
sheet.setColumnWidth(250,250);
HSSFRow Row;
HSSFCell Cell;
//Content part (doesn't matter)
IWDResource resource = WDResourceFactory.createCachedResource(
wb.getBytes(),
"workbook.xls",
WDWebResourceType.XLS);
wdContext.currentContextElement().setXls(resource);
Now after I've downloaded the XLS file, I want to open it but the file seems to be corrupt.
Image on link: http://tinyurl.com/nop52sh
When I'm pressing 2 times on 'Don't send', de excell file opens in correct form.
Any idea why?
Don't call wb.getBytes(), it doesn't do what you want. From the getBytes() javadoc
Method getBytes - get the bytes of just the HSSF portions of the XLS file. Use this to construct a POI POIFSFileSystem yourself.
Instead, if you want the overall xls file as a byte array, do
ByteArrayOutStream baos = new ByteArrayOutStream();
wb.write(baos);
byte[] xlsBytes = baos.toByteArray();
Finally, Apache POI 3.2 is ancient, over 5 years old now! You really ought to upgrade, see the changelog for an idea of all the bugs fixed since then

Text Object not supported. Java excel API

I have this piece of code to read from an xls file:
fileName = "...."
WorkbookSettings settings = new WorkbookSettings();
settings.setEncoding("Cp1252");
System.out.println("BEFORE");
Workbook w = Workbook.getWorkbook(new File(fileName), settings);
Sheet sheet = w.getSheet(1);
System.out.println("AFTER");
This is what I get in the console:
BEFORE
Warning: Text Object on sheet "Detalle" not supported - omitting
jxl.common.AssertionFailed
at jxl.common.Assert.verify(Assert.java:37)
at jxl.read.biff.SheetReader.handleObjectRecord(SheetReader.java:1811)
at jxl.read.biff.SheetReader.read(SheetReader.java:1059)
at jxl.read.biff.SheetImpl.readSheet(SheetImpl.java:716)
at jxl.read.biff.WorkbookParser.getSheet(WorkbookParser.java:257)
at MapMovInfoResource.postService(MapMovInfoResource.java:77)
The problem comes when I try to open the second sheet in that file. When I use the first sheet (w.getSheet(0)), it works fine.
Any ideas on how to solve this?
enter image description here
Its seem you have some value in excel which are not text. Please check excel value like in image, and if and special quotes are available then remove that and try again.

how to copy one workbook sheet to another workbook sheet using apache POI and java [duplicate]

This question already has answers here:
Copying Excel Worksheets in POI
(6 answers)
Closed 3 years ago.
I have one excel file with single sheet (abstract model). Now I want to copy the sheet to another existing workbook. How can I do this?
For processing regular styles and data we could iterate through each cells.
But if we have formula enabled cell,non editable cells, merged cell then this is the better solution to go for:
I have tried something like copying sheets but it didn't worked.
In addition with that i need to copy a sheet in which there are some non editable cells and formula enabled cells too.
This solution worked for me:
1)copy the entire workbook
2)delete unnecessary sheets
3)add your new sheets to above book
//input source excel file which contains sheets to be copied
file = new FileInputStream("C:\\SamepleTemplate.xlsx");
workbookinput = new XSSFWorkbook(file);
//output new excel file to which we need to copy the above sheets
//this would copy entire workbook from source
XSSFWorkbook workbookoutput=workbookinput;
//delete one or two unnecessary sheets, you can delete them by specifying the sheetnames
workbook.removeSheetAt(workbook.getSheetIndex(workbook.getSheet(" your sheet name ")));
//if you want to delete more sheets you can use a for to delete the sheets
for (int index=0;index<=5;index++)
{
workbook.removeSheetAt(index);
}
//To write your changes to new workbook
FileOutputStream out = new FileOutputStream("C:\\FinalOutput.xlsx");
workbookoutput.write(out);
out.close();

Edit existing excel files using jxl api / Apache POI

I am interested and would like to learn more about java , how to write into existing excel sheets / manipulating the existing data. I was wondering if you could give me an idea on how to edit an existing excel file and save it using the jxl api / Apache POI
or perhaps give me a sample program on how to edit some data in an existing excel file and then save it
Thanks in advance !!
The tutorials here are very helpful and well-written. They use an external JAR developed by the Apache POI project.
Here's an simple example of editing one cell:
InputStream inp = new FileInputStream("wb.xls");
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt([sheet index]);
Row row = sheet.getRow([row index]);
Cell cell = row.getCell([cell index]);
String cellContents = cell.getStringCellValue();
//Modify the cellContents here
// Write the output to a file
cell.setCellValue(cellContents);
FileOutputStream fileOut = new FileOutputStream("wb.xls");
wb.write(fileOut);
fileOut.close();
Hope it helps
One very important tip that I learned the hard way.
Open the OutputStream only after you have completed writing to your excel workbook. Zabbala's example is spot on and shows this correctly. If you open the OutputStream any earlier, your changes would not be written to the file after your program exits and you would be scratching your head as I did.
I refresh the formulas with another tab for this I use the next sentence
HSSFSheet worksheetse = workbook.getSheetAt(0);
worksheetse.setForceFormulaRecalculation(true);
but it's necesary that you apply the method setForceFormulaRecalculation for all the tabs that have the formulas.
Sorry for my English
Hello i have the same problem than neXGen. But strangely if i open the file with openoffice, it works!
Edit: perhaps i found a solution, put this after changing the values:
HSSFFormulaEvaluator.evaluateAllFormulaCells(workbook);

Categories

Resources