0

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,john.doe@example.com,123 Main StJane Smith,25,jane.smith@example.com,456 Elm AveMichael Johnson,28,michael.johnson@example.com,789 Oak RdEmily Williams,32,emily.williams@example.com,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);
}
Lokesh
  • 9
  • 1
  • When you say "I am not getting the correct HTML output", what exactly do you get? Wrong output? Or is the error triggered (2nd last line)? What does the error message say? Also, it may be a copy-paste issue with your question here but the contents of the csv file does not seems properly formatted in `let filecontent = "Name,Age,Email,Address John Doe` etc., the lines now seem to be ended with space instead of a proper newline. – Marijn Jul 31 '23 at 12:45
  • The output HTML that I'm getting is as follows: <p>This page uses frames, but your browser doesn't support them.</p> – Lokesh Jul 31 '23 at 13:02
  • This page uses frames, but your browser doesn't support them. – Lokesh Jul 31 '23 at 13:03
  • Ya file content is the copy paste issue.. – Lokesh Jul 31 '23 at 13:11
  • And which GroupDocs documentation page did you use? – Marijn Jul 31 '23 at 13:13
  • Note that the csv file formatting may still be the problem here, if it is incorrectly displayed in your question here then it may also be incorrect in your actual code, which may in turn produce the problematic output. – Marijn Jul 31 '23 at 13:15
  • I've rectified that issues in my code. but still facing same issue Name,Age,Email,Address John Doe,30,john.doe@example.com,123 Main St Jane Smith,25,jane.smith@example.com,456 Elm Ave Michael Johnson,28,michael.johnson@example.com,789 Oak Rd Emily Williams,32,emily.williams@example.com,101 Pine Lane – Lokesh Jul 31 '23 at 13:23
  • https://docs.groupdocs.cloud/conversion/convert-csv-document-with-load-options/ this documentation i m following – Lokesh Jul 31 '23 at 13:24

0 Answers0