How to generate an excel file from a PowerQuery query via java? - java

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.

Related

Is it possible to import an excel sheet as a table in the database?

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.

How to convert .xls file to .htm file using JXL api?

I have a Microsoft Excel file and I need to convert it to HTML. In excel, it is pretty simple to do: there is the "Save As..." option and you select "web page (.htm)". But I need to do this from Java, using JXL. Does anyone know how to achieve this?
Take a look at either the XML or CSV classes: they are examples of how to extract data from an Excel document and do something interesting with it.
You may also want to take a look at the Apache POI project if JXL doesn't look like it's going to meet your needs.

How can I run Excel Macro from Java?

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.

generate excel in java

I want to generate excel with enabling auto-filter option.For that I have create one template excel file by enabling auto-filter option but when I write something into that template excel file auto-filter option disabled again.
Is there any solution to create excel file by enabling auto-filter option.
Not sure if this is what you are looking for (and you don't really describe how you write the file today). "create excel file by enabling auto-filter option" doesn't really make sense to me.
There is the Apache POI that I have used for generating excel files and it works pretty well. Is that was you are using to write excel files today?
I'd have a look at Andy Khan's JExcel. I think it's the best library out there for working with Excel in Java.

upload data from excel to access using java

Can anyone give me some idea about uploading data from excel to access database using java
You'll definitely want to check out Apache POI - Java API To Access Microsoft Format Files. You'll likely find the Excel bindings you need there. For MS Access, you'll want a JDBC Driver which you can find on Sun's website. Then you can just write the glue code.
Why would you want to use Java for that? You can link Excel and Access data directly:
http://office.microsoft.com/en-us/access/HP010950951033.aspx
I've used POI before to read and write Excel files. Once you got the data, use JDBC (maybe the JDBC/ODBC bridge) to load it into Access.

Categories