Best way to convert excel file into a JSON file?

9gt*_*3wS 4 javascript excel json aws-lambda

I have data saved in a Microsoft excel file. I need to turn that data into something that a Lambda function can parse.

I think the best way to do this is to convert the excel file into a JSON file (and then my Lambda function can read and parse it).

What's the best way to do this?

To convert the excel data file into a JSON file, I have found some handy online converter tools, like this one. It seems to work.

However, that converter and others add in \r wherever there are line breaks in the data, and \ wherever there are quotes in the data. (the line breaks and especially quotes need to be in the data)

So to properly read the data in the JSON file, I have to then get rid of these changes to the raw data.

Is there another way to do this? Such as a converter that does not change the raw data in this way? Or some method other than a converter?

一旦原始数据被更改(通过添加像我上面提到的那样的东西\r\,删除它就变得很麻烦。我可以进行查找/替换来消除更改,但这会增加一些步骤,这些步骤可能会变得非常耗时。使用正则表达式可以增加性能。

**编辑:请注意,我可能需要一种创建实际文档的方法(因此在客户端浏览器中生成数据的程序将无法工作)。我希望创建一个实际文档,然后我的 Lambda 可以对其进行分析。**

小智 12

要从 Excel 工作表创建 json,我通常使用 excel 在 excel 工作表中准备 json CONCAT,然后复制它。对于 headers 来说,这可能不是一个完美的方法,但是对于通常构成 json 较大部分的键和值来说,它效果很好。

在此输入图像描述

=CONCAT(CHAR(34),A2,CHAR(34),":",CHAR(34),B2,CHAR(34))
Run Code Online (Sandbox Code Playgroud)

请注意,它CHAR(34)代表" 所有行,您可以将其从角落向下拖动。

  • 我只需在末尾添加一个逗号即可使其工作 `=CONCAT(CHAR(34),A2,CHAR(34),":",CHAR(34),B2,CHAR(34),",") ` 除了最后一行。 (2认同)