I've .txt files generated by Java (with databases queries). I need to generate an excel with that (with graphics and other kind of information, is not just a pure csv).
How can I call my excel macro using java?
I would say, have your Excel macro use the csv as a data source and let it do it's job directly.
Otherwise you might want to look into a reporting framework like jasper reports http://community.jaspersoft.com/project/jasperreports-library
You need to use a JAVA-to-COM bridge, such as Jacob. http://danadler.com/jacob/ there are other out there but I am familiar with Jacob. Then you would be able to start the application, load the file, run the macro, and then close the application. This should get you started.
Why not create an excel directly using java apache poi, instead of creating txt and then converting txt excel using macro.
Related
I am generating a metaquery created with the PowerQuery syntax, and I would like to use some library to generate an excel file from there.
I have tried POI and Docx4j with no success. Any advice would be helpfull.
Thanks in advance.
I'm not aware of any Java libraries that can add Power Query queries to an Excel file. The structure inside of the Excel file is documented here, so you could implement yourself, or request a library developer to implement it.
You can use VBA to automate creating queries in Excel 2016 https://gallery.technet.microsoft.com/office/VBA-to-automate-Power-956a52d1
Maybe you could use java to send a message to some VBA running in the Excel workbook, or to generate some VBA script that runs when you open the workbook, and have the VBA actually create the query?
Edu says: store the query in the windows clipboard and then generate the query via VBA in excel with a macro.
This is the first time that I am attempting this, and I don't know if it is possible. I am trying to develop an application that allows me to upload an excel file directly into a database.
Is it possible to upload the excel data without first converting the excel sheet to the CSV format? The database table contains fields and columns with the same names as the excel file.
Does anyone know of a tool which can do this for me?
it is certainly possible. You might be interested in the JBoss Teiid project, which enables accessing Excel spreadsheet like it was a table.
Given that, you can then easily fill all the values from a "virtual" table formed from the spreadsheet (let's call it excelTable) into another table (let's call it targetTable):
INSERT INTO targetTable(column1,...) SELECT column1,... FROM excelTable;
The project is open-source so if its usage doesn't fit your needs, you can always look at the sources and maybe get an inspiration, how you can do such things.
Best regards
Jan
For Oracle, the easiest way is to use sqlldr for bulk load.
So you need an application that will parse the xls/xlsx and write a data file for sqlldr (can be csv, in fact any delimited text file).
If you really don't want to convert the file you could parse it and insert each row at a time, but this method is very slow when dealing with a lot of data.
Sqlldr FAQ
EDIT: Equivalent tool for sqlserver is called BCP
BCP Tool
And of course, you can use the tools withouth any software attached, running them via command lines once you have the data and/or control files ready.
Are there any libraries out there that can be used to generate line-graphs and export them to a .xls file?
Check out Apache POI (http://poi.apache.org/). However you need to use a limited workaround for this to work.
"You can not [sic] currently create charts. You can however create a chart in Excel, modify the chart data values using HSSF and write a new spreadsheet out. This is possible because POI attempts to keep existing records intact as far as possible." (http://poi.apache.org/spreadsheet/limitations.html)
You could also look into using the JExcelAPI (http://sourceforge.net/projects/jexcelapi/), but I have no familiarity with its limitations.
We have a system which generates reports in XLS using Spreadsheet_Excel_Writer for smaller files and in case of huge files we just export them as CSVs.
We now want to export excel sheets which are multicolor etc. as a part of report generation, which in excel could be done through a few macros.
Is there any good exporter which generates the excel sheets with macros?(Spreadsheet_Excel_Writer cant do this) If it exists for PHP it would be amazing but if it exists for any other language, its fine we could interface it.
It's your "excel sheets with macros" that is going to cause you all end of problems. If you're on a Windows platform, with Excel installed, then PHP's COM extension should allow you to do this. Otherwise, I'm nor aware of any PHP library which allows you to create macros... not even PHPExcel. I suspect the same will apply with most languages, other than perhaps those running with .Net (and possibly Mono).
However, do you really need macros to play with colour? Can't you do this more simply with styles, and perhaps conditional formatting?
PS. What's your definition of "huge"?
I have an Excel file with manual input functions, which use an add-in from a third party. I want to use the functionality of the Excel file in Java. I could think of two ways of doing it:
code the functions in VBA, or VB with Excel reference, then generate .dll or .exe files for Java to use.
Feed data to an Excel file using jxl (would Excel file update automatically when it receives new data?), then read the new result every time from the Excel file.
I don't have much experience with Excel or VBA. I want to know which method is more doable and faster.
As your code is invoking a third-party add-in and is needs that for correct operation, then you will need to go the VB route or access Excel via the Automaton API (from Java, using for example, Com4j).
The reason is that the pure-java excel readers (jxl, Poi, xlSQL etc..) all use java to emulate the built in functionality of excel, but of cousre they cannot emulate third party add-ons.
Reading excel files using com4j is discussed in this thread.
Obba allows you to make calls from an Excel cell to a Java virtual machine (which may run on a different computer, if necessary). The JVM has to run Obba server (provided as a Java with main() method). The Obba server can load other JARs an instantiate objects via functional calls form the Excel sheet.
You could also use Obba to pass values, results to a Java code (or server).
(You may contact me, if you are interested in exploring this and need assistance (I work on Obba).