Background: I have a JAVA program and I import an Excel document to my JAVA program to do some "calculations".
Sometimes it is important to open the Excel file (with Excel) and jump to a special row.
My question is, is there an option to open Excel with "a link" to select a special row ?
Like
"D:\Documents\Table.xlsx?sheet=sheet1&row=12345"
to select Sheet "sheet1" and jump to row "12345".
I can not modify the Excel document to add macros or something else.
Any ideas ?
Related
I want to search data in excel sheet by using Java program.
Condition:
Write search data in text field and press Jbutton for search.
Textfield data goes to excel file and find row who contain matching data.
Row data copy and move to java program and Copy in 1 and more Textfield.
You better use macros to achieve this functionality.
I am having trouble implementing properties to a .csv file when I export it through Java. I will mainly be using the .csv in Excel. Is it possible to give bold text or any sort of properties to a .csv file in Java? Specifically, I want to give a background color to certain cells and make some text bold to differentiate the cells from other cells. For example, I want to make the first row in the .csv file bold to show that the first row is like a header.
One restraint, I want to avoid using any API's from the internet.
If you want bold or other features to show up in Excel you need to create an excel file. csv means Comma delimited file. All it has is data separated by commas. No formatting what-so-ever.
I have requirement in that i have to read and validate the excel file and insert to data base, initially i am reading the file and inserting it to database, if the data already there in database, i am returning row and column numbers of the duplicates from database, i need to change the color of those cells based on the row and column numbers.
can any one please help me to solve this problem. or can suggest any idea how to read/ write and validate excel file, (validation in the sense i need to compare the data in the excel file with the data in the database).
currently i am using apache poi
This answer is for .xls; the API for xlsx is very similar, though.
Reading the Excel file is easy, open a FileInputstream for the file, then create a HSSFWorkbook
HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
To change to color of some cells, you first have to create a Style with this color (changing the style of a cell will also change some other properties, like the font etc., so things might get a bit messy here, but that's how excel works)
colorStyle = workbook.createCellStyle();
colorStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
colorStyle.setFillForegroundColor(HSSFColor.RED.index);
Now you have to loop through the rows in all workbooks, identify the duplicates, and change the style of those cells:
cell.setCellStyle(colorStyle);
Finally, you write the workbook to a new file, through a FileOutputStream
workbook.write(outputStream);
I have a generic problem with a not-so-generic requirement.
I have to convert an Excel file into PDF with a catch that all the formatting of each cell in the excel file has to be retained as it is. No change allowed. Like if a cell is formatted as Currency/Accounting then by default negative values are displayed in round braces e.g.(8.5) but when read from Java the value is -8.5. For numeric cell, value would be 0 but is displayed as hyphen (-).
Similarly for rest of the formatting types, the display changes.
As the cell has different cell types and the actual value in the cell is displayed according to the formatting applied on the cell, how to copy it in output PDF file?
Latest I learnt that DataFormatter is much useful in my case. So I wrote below code
DataFormatter df = new DataFormatter();
Cell c = row.getCell(i);
CellStyle style = c.getCellStyle();
cellvalue = df.formatRawCellContents(row.getCell(i).getNumericCellValue(), style.getDataFormat(), style.getDataFormatString());
One of the cell has formatting ($* #,##0.00);($* (#,##0.00);($* "-"??);(#_) (0x2c). If the value in the cell is 0 then ideally it should display "-" but it displays as 0.0 only.
Any help would be appreciated.
First install the pdf software in your local system then run this code in excel vb application. Give the name as you wish... that's it..
Sub expf()
Application.ActivePrinter = "PDF Complete on PDFC"
ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,""PDF Complete on PDFC"",,TRUE,,FALSE)"
End Sub
Using POI jar we can read excel . After reading for each row you can create PDF files using PDFBox. Also based on your requirements apply the styles for the pdf.
i am developing one desktop application with the functionality of exporting jtable content into an excel file.
Now here is the flow of project code that i am implementing:-
After importing jtable into excel, data is written in this way:- (only single record is in jtable)
Now here all data is exporting in proper way except OUR REMARKS & CLIENT REPORT.
I have also tried to implement setLineWrap() and setWrapStyleWord() but still its not working.
Here is my code for above functions for OUR REMARKS textarea:-
txtOurRemarks.setLineWrap(true);
txtOurRemarks.setWrapStyleWord(true);
Can anyone help me out in this?
Thanks.
I would guess the problem is that you have new line characters in your output file. So you would need to replace those characters with a blank character so they appear together on a single line in Excel.