CSV is not converting in html using groupdocs

71 Views Asked by At

I am using the GroupDocs Conversion Cloud API to convert a CSV file to HTML in Node.js. I have followed the code provided in the GroupDocs documentation, but I am not getting the correct HTML output from the CSV. Can somebody help me identify where the issue might be in my code.

const conversion_cloud = require("groupdocs-conversion-cloud");

let fileApi = conversion_cloud.FileApi.fromKeys(clientId, clientSecret);

let filecontent = "Name,Age,Email,Address John Doe,30,[email protected],123 Main StJane Smith,25,[email protected],456 Elm AveMichael Johnson,28,[email protected],789 Oak RdEmily Williams,32,[email protected],101 Pine Lane";


let uploaRequest = new conversion_cloud.UploadFileRequest('./spread.csv', filecontent);

await fileApi.uploadFile(uploaRequest).then(async (result, err) => {
  if (err) {
    console.log("upload- ", err);
    return res.status(500).send(false);
  } else {
    console.log("document uploaded", result);
  }

  let loadOptions = new conversion_cloud.CsvLoadOptions();
  loadOptions.separator = ",";
  loadOptions.convertDateTimeData = true;

  let settings = new conversion_cloud.ConvertSettings();
  settings.filePath = './spread.csv';
  settings.format = "html";


  convertOptions = new conversion_cloud.HtmlConvertOptions();
  convertOptions.fixedLayout = false;
  convertOptions.usePdf = false;

  result = await convertApi.convertDocument(new conversion_cloud.ConvertDocumentRequest(settings));
  console.log('CSV file converted to HTML successfully.');
  return res.send(data);
}) catch (error) {
  console.error('Error converting CSV to HTML:', error);
}
1

There are 1 best solutions below

0
On

Your reported issue is fixed in GroupDocs.Conversion Cloud 23.10. Please try the latest version of GroupDocs.Conversion Cloud SDK for Node.js.

Convert CSV to HTML in Node.js

// load the module
var GroupDocs = require('groupdocs-conversion-cloud');
var fs = require('fs');

// get your appSid and appKey at https://dashboard.groupdocs.cloud (free registration is required).
var appSid = "xxxxx-xxxx-xxxx-xxxx-xxxxxxx";
var appKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";

const convertDocument = async () => {

// construct Api
var convertApi = GroupDocs.ConvertApi.fromKeys(appSid, appKey);


try {
    const format = "html";
    const loadOptions = new GroupDocs.CsvLoadOptions();
    const csvContent = fs.readFileSync('Test_cust.csv');
    loadOptions.format = "csv";
    loadOptions.separator = ",";

    const convertOptions = new GroupDocs.WebConvertOptions();
    convertOptions.zoom = 100;

    const request = new GroupDocs.ConvertDocumentDirectRequest(
      format,
      csvContent,
      undefined,
      undefined,
      loadOptions,
      convertOptions);

    // convert document directly
      const result = await convertApi.convertDocumentDirect(request);
    console.log(result);
    fs.writeFileSync("CsvtoHTML.html", result);

} catch (err) {
throw err;
}
}

convertDocument()
.then(() => {
console.log("Document converted successfully");
})
.catch((err) => {
console.log("Error occurred while converting the document:", err);
})