We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to read XLSX file using jdk 1.4

Hi,

I am trying to use Aspose-cell-2.5.2 to read xls and xlsx files. But I am not able to write the code to use Aspose-API as I am using it for the first time . So can you help me to do this ?

Hi,

Please use our latest version v7.1.0:

http://www.aspose.com/community/files/72/java-components/aspose.cells-for-java/entry355902.aspx

Check the documentation topics (in the sections) for the product on how to read/write files or data, e.g

http://docs.aspose.com/display/cellsjava/Your+First+Application+using+Aspose.Cells+++Hello+World

Loading, Saving, Converting and Managing

Working with data

Also, just for your knowledge, there are some other jars (with component’s main jar file) which are used in our component for XML related operations, the following jars are there in the release archive’s “\lib” folder, e.g:

dom4j

stax2-api

woodstox-core

jsr173_1.0

bcprov-jdk

//etc.

Please make sure that you have also set these jars into your class path with component’s main jar file.

For complete reference check the “README_LIB.txt” file in the release archive.

Thank you.

Thanks for your reply :)

Does the latest version support jdk 1.4(as per my requirement) . What are the jar file I need to use ? What are the packags i need to import in my class?

Hi,


Yes, you need to use/set class path for jar files in the “…\jdk1.4\lib” folder in the release archive.
There is only one package that you need to import, e.g

import com.aspose.cells.*;

For complete reference see the Aspose.Cells for Java API Reference pages:
http://docs.aspose.com/display/cellsjava/Aspose.Cells+for+Java+API+Reference


Thank you.

Thanks a lot for your reply.

Started grtting some points about Aspose :) .....

But can you tell me what wrong with the code given below

import com.aspose.cells.*;

import java.io.IOException;

public class TestRead {

public static void main(String[] args) throws IOException {

String path = "C:/Documents and Settings/abc/Desktop/Book";

Workbook workbook = new Workbook(path);

Worksheet sheet = workbook.getWorksheets().get(0); ............................... here getting error

Cell cell = sheet.getCells().get("Name"); ......................................................... name of columns in excel sheet

Here I am trying to read all the values under column "Name"

Hi,


I am not sure about your code, are you getting some named range, if so, kindly check the topic for reference:
http://docs.aspose.com/display/cellsjava/Named+Ranges

Also, make sure that the Workbook has one sheet, by the way what is the error you get, please paste complete error message or stack trace etc. We will be in better position to help you.

If you need to get values from a column, say A column, a simplest example can be you have to loop through all the cells in that column, e.g

Sample code:
//Instantiating a Excel object by excel file path
Workbook excel = new Workbook("e:\\test\\book1.xls");
//Accessing the first worksheet in the Excel file
WorksheetCollection worksheets = excel.getWorksheets();
Worksheet worksheet = worksheets.get(0);

//Browse the A column in the sheet
for(int i = 0; i< worksheet.getCells().getMaxRow(); i++)
{
System.out.println(worksheet.getCells().get(i,0).getStringValue());

}


Thank you.

Hi,

Even I am facing some error in your sample code in the following line:

Worksheet worksheet = worksheet.get(0);

It says method get(int) is undefine for the type of Worksheet.

Please clearify it. :)

Hi,


I actually wrote:
Worksheet worksheet = worksheets.get(0);

Also make sure that you are using latest Aspose.Cells for Java version v7.1.0.

Thank you.

Hi,

Thanks a lot for replying ....

What code should i add into the above code to read all the columns and rows in excelsheet ? The code you have given as example reads only one column . So what if i want to read all values ?

Thaanks once again :)

Hi,

I have updated my previous sample code a bit for your requirement now, see the following code:

Sample code:
//Instantiating a Excel object by excel file path
Workbook excel = new Workbook("e:\\test\\book1.xls");
//Accessing the first worksheet in the Excel file
WorksheetCollection worksheets = excel.getWorksheets();
Worksheet worksheet = worksheets.get(0);

//Browse all the cells in the rows/columns in the sheet
for(int i = 0; i< worksheet.getCells().getMaxRow(); i++)
{

for(int j = 0; j< worksheet.getCells().getMaxColumn(); j++)
{
System.out.println(worksheet.getCells().get(i,j).getStringValue());
}
}


Thank you.