I'm writing a portlet web app to allow user upload a excel file, and then the backend will do the validation to the excel file and convert the content into sql statement
The back-end is using java with library aspose.cells to handle the excel access.
The problem is, how can I pass the excel to back end to access.
Now I've think of after user upload the excel file, the back end first will download the excel file to local (maybe C:\temp), and then it can directly read the excel file from C:\temp rather than server file.
But it's possible to do it?
You seem to be looking for some sample code where you may upload an Excel file and then using Aspose.Cells for Java, process this uploaded file. You may have a look at the following link where a tutorial is there for uploading files using portlets.
http://www.codeyouneed.com/liferay-portlet-file-upload-tutorial/
Once the file is uploaded, use com.aspose.cells.Workbook class object for loading this stream directly into Workbook and then process it as per your requirement.
Following is the link to sample code for loading Excel file (in stream) into Workbook object:
https://docs.aspose.com/display/cellsjava/Opening+Files+with+Different+Formats#OpeningFileswithDifferentFormats-OpeningthroughStream
Note: I am working as Support developer/ Evangelist at Aspose.
Related
I need to download some data in webpage in the form of excel file for that webpage contains excel image button. When i click the button an excel file downloads with containing some data which i need. But when i tried to open the downloaded file it showing an error "The file you are trying to open , File is in different format then specified by the file extension or corrupted data. Because of this error i am unable to read the data by using java.
try to save it as xlsx as there are two kind of work book provided by poi that is for xls and another is for xlsx.
Is there any way to update excel content in background when the sheet is in open state.
I am using Apache POI Spreadsheet API (java based API) to read and write content in excel sheet.
By using user API, I am saving data to excel sheet, but I didn't find any API to update excel data in background(without closing excel file, content should be updated).
If we try to update excel when it's open it'll show error like file is accessed by other resource.
Please help me to find an API to achieve this by using Apache POI or any other API.
(I observed by using VB script we can achieve this. but first preference is Java, if there is no other API available then VB Script).
Excel puts a lock on the file and thus actively prevents other applications from changing the file, so I don't think this is possible with any library.
I am using GWT with java. in my application i should upload excel file and should read the content of excel file and store data in entity. I have multiple columns in my excel sheet and i need to map them with my fields in the entity. please suggest me how to achieve this. for example : I have customer Names in excel sheet i need to save them in database/entity on click of button
any help.
For uploading a file you need a multipart upload form.GWT supports this with the FormPanel and the FileUpload widget.
If the server implementation is done in Java, you need an Servlet that handles the upload. Apache Commons Fileupload will help you handling the request.
As mentioned above Apache POI can help parsing the Excel document.
You can upload excel file as any file. The detailed gwt example you can find here
http://www.celinio.net/techblog/?p=1207
To read from excel you have to use Apache POI APIs for microsoft docs.
https://poi.apache.org/
You can use the following example to make yourself familiar with the excel api's
How to read and write excel file in java
We are developing application in JAVA AND using APACHE POI 3.6 for accessing Ms-Excel files. Suppose,my Excel file is opening, when running my program, then it raising the error and program terminated.So, First i want to check that whether my excel is opened or not.If it is opening, then i want to close my excel file and then open and read that file...
POI does not run Excel at all. It is independent code that opens your excel file and interprets the contents. There is no straightforward way for you java code to communicate with Excel and check to see if it is running. You can look into Java/COM bridges for complex mechanisms for trying to coordinate.
I think the best you're going to be able to do from within Java is to check if someone has the file locked for editing using the canWrite() method of the File class.
You're not going to be able to force the user to close the excel file though. If the application has a GUI you could post a message to the user requesting they close the file manually.
I have a file uploader module. The UI is created using simple HTML and Javascript.
Server side I am using Java code. I want to check the type of the uploaded file.
Files don't really have types. The best you can do would be to attempt to load the file as an XLS.
If the load succeeds, the file is most likely an XLS.
If the load fails, the file is either an invalid/malformed XLS, or not an XLS at all.
You can also look at the uploaded file name or the content type, but neither of these is definitive; i.e. they might say that the file is an XLS when it is something completely different.