Free Support Forum - aspose.com

Csv to xls

Hello,


I’m using aspose.cells for java on iSeries.
In the newer versions of aspose it’s possible to create a xls starting from a csv-file.

Can somebody tell me which parameters to pass to “CreateWorkbook” ?
I tried to pass a string (=csv-file) + loadoptions object, but without success.

I tried FileInputStream object / Loadoptions, but without success, …

Thanks in advance !!

Hi,

Thanks for using Aspose.Cells for Java.

It seems you are using PHP, I have attached the PHP file that contains all the overloads and wrapper classes for your help.

You will have to look into them and write your PHP code that makes use of Aspose.Cells for Java using its wrapper classes.

Since you are using the LoadOptions Workbook constructor, so the following lines of wrapper functions/classes are relevant for you.


/*
create new wrapped class [Workbook] for java version [com.aspose.cells.Workbook]
WARNNING
the parameter[oInputStream0] maybe has no Php-wrapper.

@param oInputStream0 corresponding java type is {java.io.InputStream}
@param oLoadOptions1 com.aspose.cells.LoadOptions
/
static function create4Workbook($oInputStream0, $oLoadOptions1)
{
$workbook = new Java(‘com.aspose.cells.Workbook’, ClassFactory::_t1($oInputStream0), ClassFactory::_t1($oLoadOptions1));
return new Workbook($workbook);
}

/

create new wrapped class [Workbook] for java version [com.aspose.cells.Workbook]

@param oString0 String
@param oLoadOptions1 com.aspose.cells.LoadOptions
*/
static function create5Workbook($oString0, $oLoadOptions1)
{
$workbook = new Java(‘com.aspose.cells.Workbook’, $oString0, ClassFactory::_t1($oLoadOptions1));
return new Workbook($workbook);
}


Please also see the following Java code that converts csv file into xls for your help, which you can convert into PHP.

Java

String filePath = “F:\Shak-Data-RW\Downloads\source.csv”;


//LoadOptions for CSV format

LoadOptions opts = new LoadOptions(LoadFormat.CSV);


//Create a workbook from CSV file

Workbook workbook = new Workbook(filePath, opts);


//Save the CSV file into Xls format

workbook.save(filePath + “.out.xls”, SaveFormat.EXCEL_97_TO_2003);

Hello,


Thanks for your help.
I tried your example, but without success :frowning:

Creating a workbook with the specified parameters does not work -->
received Java exception "java.lang.NoSuchMethodError: " when calling
method “” with signature
“(Ljava.lang.String;Lcom.aspose.cells.LoadOptions;)V” in class
“com.aspose.cells.Workbook”.

What am I doing wrong ?

Thanks !

Hi,

Please make sure you are using our recent fix i.e Aspose.Cells for Java 7.3.3 with the attached php wrapper to execute your code. We used a simple php file to test your situation and found no failure.

The csv file can be read fine. Our php code is like following:

PHP

<?php
require_once("java/Java.inc");
require("AsposeCells.php");

$workbook = ClassFactory::create3Workbook("d:/temp/t.csv");
$cell = $workbook->getWorksheets()->getI(0)->getCells()->getII(0, 0);
echo $cell->getValue();
echo "exec over.";
?>

Hello,


I’m not using PHP.
I’m using the java class.

Can you provide me the correct workbook constructor ?
What do I need to pass ?
Path + loadoptions ?

Thanks !

Hi,


Here is the simplest lines of code that converts a sample CSV file to XLS file format. Please make sure that you are using latest version/fix e.g v7.3.3

[JAVA]

String filePath = “source.csv”;
//LoadOptions for CSV format
LoadOptions opts = new LoadOptions(LoadFormat.CSV);

//Create a workbook from CSV file
Workbook workbook = new Workbook(filePath, opts);


//Save the CSV file into XLS format
workbook.save(filePath + “.out.xls”, SaveFormat.EXCEL_97_TO_2003);

Thank you.

Hi,

If you are using the Java, then I have already provided the code. The code works fine with Eclipse.

I am not sure about your System Environment and how to execute the above code.

Aspose.Cells for Java is just a JAR file, if you can execute other JAR files, then you can also execute Aspose.Cells for Java code give in the above post.

You should search on internet how to execute any JAR code in your Environment.

Please also note, Aspose.Cells for Java also needs some other prerequisite libraries. You should add these libraries in your class path.

  1. bcprov-jdk16-146.jar
  2. dom4j-1.6.1.jar
  3. stax2-api-3.0.2.jar
  4. woodstox-core-asl-4.1.1.jar

Also, provide us your screenshot of error, it could also help us look into your issue further.