0

I am using an API to get data in excel in office.js by creating a function in Javascript. I am able to see all the data of the API but I want that to be in proper format of rows and columns like: Id, name, symbol so on.. screenshot of the result am seeing now

Rick Kirkham
  • 9,038
  • 1
  • 14
  • 32
Vishwesh
  • 11
  • 5
  • I've deleted my original answer because you revealed in a comment to it, that your working with Excel custom functions. That changes things. You can't use the Excel.js object model with custom functions. I'll add the custom functions tag to your question, but please edit the question to make clear that you are creating a custom function. – Rick Kirkham Aug 30 '19 at 17:18

1 Answers1

0

Have you considered exporting using a .csv file? You can use array evaluation to append each column item to each row, followed by a comma, and end each line with the newline character. Your very first row would be your headers. .csv files can be opened directly by Excel.

Alex Marks
  • 66
  • 7
  • Thanks for the reply. I don't want to open as .csv. I even tried other alternatives but somehow its not working. – Vishwesh Aug 28 '19 at 13:51
  • Opening a .csv with Excel, or importing a .csv into Excel, separates columns at the commas and rows at the newline character. If you intend to have commas in your data you can use tab-separated instead of comma-separated. Then in your export algorithm just put a `,` or `` after each entry and `/n` after each row. I always use a constant string for headers (like `"Id,Name,Symbol"`). I've done this inside an Android app and then shared the generated spreadsheet via email/drive and opened with Excel on desktop. Works like a charm. – Alex Marks Aug 29 '19 at 14:38