Code for excel to html conversion using Aspose.Cells for cloud


#1

import com.aspose.cells.api.CellsApi;
import com.aspose.cells.model.ResponseMessage;

import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class ExcelToHtml {

public static void main(String[] args) {
    CellsApi slidesApi = new CellsApi("MY_API_KEY", "MY_SID", false);
    String password = "";
    String format = "html";
    String outPath = "";
    String saveOption = "<HtmlSaveOptions></HtmlSaveOptions>";
    try
    {
        ResponseMessage apiResponse = slidesApi.PutConvertWorkBook(format, password, outPath, new File("path_of_file), saveOption);
        if (apiResponse != null)
        {
            InputStream responseStream = apiResponse.getInputStream();
            final Path destination = Paths.get("test.zip");
            Files.copy(responseStream, destination, StandardCopyOption.REPLACE_EXISTING);
        }
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}

I am getting error as -
com.aspose.client.ApiException: {“Message”:“Expected two parts in the MIME multipart request. One for document and second for save options.”}
at com.aspose.client.ApiInvoker.invokeAPI(ApiInvoker.java:259)
at com.aspose.cells.api.CellsApi.PutConvertWorkBook(CellsApi.java:7341)
at com.alphasense.docconverter.ExcelToHtml.main(ExcelToHtml.java:26)

Please help me in understanding how to convert excel to HTML using aspose.cells for cloud
}


#3

@poojard

We were able to observe the issue. The following URI

GET
http://api.aspose.cloud/v1.1/cells/sampleExcel.xlsx?format=html

returns the HTML but do not return the linked files folder. It should return the Zip file which user could use to extract entire HTML and its relevant files. We have logged this issue in our database for product team investigation. We will look into it and provide you a sample code and update you asap.

This issue has been logged as

  • CELLSCLOUD-10088 - Code for Excel to Html conversion using Aspose.Cells for Cloud

#4

@poojard

Thanks for using Aspose APIs.

Please first upload this sample Excel file and then use the following URI, it will then return you a ZIP file containing output HTML and its linked resources.

Download Links:
Sample Excel File.zip (13.6 KB)
Returned Output.zip (26.4 KB)

Here is the URI. Please don’t forget to sign it using your App SID and App Key

GET
http://api.aspose.cloud/v1.1/cells/Book1.xlsx?format=html

Let us know if you face any error. We will look into your issue and help you asap.


#5

I’m trying to download a spreadsheet, but having trouble reading the ZIP file correctly due to encoding issues I believe.

You are not specifying the encoding you are using in your response. I’ve tried UTF-16 and UTF-8 respectively, but without luck.

Could you let me know the correct encoding I should use?

{:headers {"cache-control" "private", "content-disposition" "inline; filename=aspose-chart.html", "content-type" "application/zip", "date" "Tue, 06 Mar 2018 14:33:17 GMT", "server" "Microsoft-IIS/8.0", "x-aspnet-version" "4.0.30319", "x-powered-by" "ASP.NET", "content-length" "22975", "connection" "keep-alive"}, :status 200, :body "..."}

Thanks!


#6

@alpeware

You don’t need to apply any encoding. Simply unzip the file using the default Archive/Extractor software of your Operating System (Windows or Mac OSX).

Input Files: myWorkbook.xlsx.zip (38.4 KB)
Output Files: Workbook.zip (33.6 KB)

Please use our SDKs to test our APIs.

P.S. Input file is zipped because Discourse does not allow to upload .xlsx file.


#7

OK, thanks. I’m somehow messing up the encoding along the way resulting in a corrupt archive on my end.

I’m using the REST API directly as my language of choice - Clojure - is not directly supported by any of the SDKs currently.


#8

@alpeware

While converting Excel document to HTML, the API returns zipped file instead of HTML because the HTML document contains multiple files, zipping them makes it convenient for returning multiple files.