Covert Excel file to Html format

when we use aspose.cells,we have some problems:
License license = new License();
license.setLicense(“C:\Users\Lixp\Desktop\Aspose.Total.Java.lic”);
Workbook workbook = new Workbook(new FileInputStream(
“C:\Users\Lixp\Desktop\xlsx.xlsx”));
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.setAttachedFilesDirectory(“test”);//doesn’t work
// saveOptions.setAttachedFilesDirectory(“C:\Users\Lixp\Desktop\test”);
saveOptions.setCreateDirectory(true);//doesn’t work too
saveOptions.setAttachedFilesUrlPrefix(“test”);///doesn’t work too
workbook.save(new FileOutputStream(“C:\Users\Lixp\Desktop\16.html”),saveOptions);
it cann’t generate attach files
it works well if only i save(“C:\Users\Lixp\Desktop\16.html”,saveOption),
but our api only supply OutputStream to Aspose Convertion client.

Hi,


I have tested using setAttachedFilesDirectory() method and it works fine. the pictures, binary objects etc. are saved to the folder that I specified in it. Here is my sample code, I am using a simple Excel file that contains some pictures and charts in it, the pictures are saved in specified folder. For your information, the method would save the relevant binary data (in the form of images) for the pictures, charts or other binary objects contained the Excel file into the specified folder. I am using our latest version/fix: Aspose.Cells for Java v8.2.2.1 for testing your scenario.
e.g
Sample code:


Workbook workbook = new Workbook(new FileInputStream(“Book1.xlsx”));
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.setAttachedFilesDirectory(“F:\Files\myfolder1”);
workbook.save(new FileOutputStream(“out1.html”),saveOptions);

Thank you.

We used Aspose.Cells for Java v8.1.0.We have purchased Aspose.Total for Java.Can we use the license in 8.2.2.1?

Maybe you didn’t know what i mean.I means that when we use save(String,SaveOptions),eg,save(“C:\Users\Lixp\Desktop\xlsx.html”,new HtmlSaveOptions()),we can generate xlsx.html and (xlsx_files folder and the files in it).But when we use save(OutputStream,SaveOptions),we get only xlsx.html. and We also want to control the xlsx_files’s folder name.How to do?

Hi,


Well, we you may implement IStreamProvider interface accordingly for your needs. By using the interface you can specify all details for saving different parts for the resultant HTML etc. Please see the sample demo code for your reference, so you could write your own codes accordingly.
e.g
Sample code:

String path = “f:\files\Book1.xlsx”;
final String prefix = “…\IMG\”;
Workbook book = new Workbook(path);
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
options.setExportActiveWorksheetOnly(true);
options.setStreamProvider(new IStreamProvider() {
public void initStream(StreamProviderOptions options) throws Exception {
File f = new File(prefix + options.getDefaultPath());
// the CustomPath which customer sets should be same with the path which the file saves.
// whether CustomPath is a relative path or an absolute path, it must point to the same location with the path which file saves.
options.setCustomPath(f.getCanonicalPath());
f.getParentFile().mkdirs();
// setting the stream which the file will be saved into.
options.setStream(new FileOutputStream(f));
}
public void closeStream(StreamProviderOptions options) throws Exception {
options.getStream().close();
}
});
book.save(“f:\files\out1.html”, options);


Hope, this helps a bit.

Thank you.

License license = new License();
license.setLicense(“C:\Users\Lixp\Desktop\Aspose.Total.Java.lic”);
Workbook workbook = new Workbook(new FileInputStream(
“C:\Users\Lixp\Desktop\xlsx.xlsx”));
FileOutputStream fOutputStream = new FileOutputStream(
“C:\Users\Lixp\Desktop\xlsx.html”);
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
final String resourceFolder = “C:\Users\Lixp\Desktop\xlsx_files”;
saveOptions.setAttachedFilesUrlPrefix(“test”);
saveOptions.setAttachedFilesDirectory(resourceFolder);
saveOptions.setExportActiveWorksheetOnly(false);
saveOptions.setStreamProvider(new IStreamProvider() {

@Override
public void initStream(StreamProviderOptions providerOptions)
throws Exception {
// providerOptions.getDefaultPath()//here null(resourceName),
String customPath = resourceFolder
+ providerOptions.getDefaultPath().replace(“null”, “”);
File customFile = new File(customPath);
if (!customFile.getParentFile().exists()) {
customFile.getParentFile().mkdirs();
}
providerOptions.setCustomPath(customFile.getCanonicalPath());
providerOptions.setStream(new FileOutputStream(customFile));
}

@Override
public void closeStream(StreamProviderOptions providerOptions)
throws Exception {
OutputStream outputStream = null;
try {
outputStream = providerOptions.getStream();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (outputStream != null) {
outputStream.close();
}
}
}
});
workbook.save(fOutputStream, saveOptions);




html source code:













so we cann’t view it.we want to control resource uri,how to do? because we want to view them on webapplication.
and also we want to control all html conversion’s resource uri.we mean that we can control all resource uri by a parameter.

Hi,


Thanks for your sample code.

We are not entirely sure about your specific requirements, could you elaborate your needs in details and what is the issue you are facing with the code segment. Also provide us your template Excel file and output HTML file in a zipped archive, we will check it soon.

Thank you.