Datatables/TableTools:导出到 Excel 时将数据格式化为文本 [英] Datatables / TableTools: format data as text when exporting to Excel
问题描述
我正在使用 Datatables TableTools 插件,以便为我页面上的表格提供导出到 Excel"选项.
I am using the Datatables TableTools plugin in order to provide an Export to Excel option for a table on my page.
总的来说,一切都按预期工作.我唯一的问题是我需要所有数据.结果 Excel 表中的列被格式化为文本,否则我会丢失某些列中的数据.
In general everything works as intended. My only issue is that I would need all the data resp. the columns in the resulting Excel table being formatted as text as otherwise I am losing data in some columns.
示例:- 我有一列有前导零(例如 0022
),如果它没有格式化为 Excel 文件中的前导零(例如 22
)文本.- 另一列包含 19 位帐号(例如 1234567890123456789
),如果不是,则在 Excel 文件中显示的最后四位数字将更改为零(例如 1234567890123450000
)格式化为文本.
Examples:
- I have a column that has leading zeros (e.g. 0022
) which only appears with the leading zeros cut off (e.g. 22
) in the Excel file if this is not formatted as text.
- Another column contains 19-digit account numbers (e.g. 1234567890123456789
) which appears with the last four digits being changed to zeros (e.g. 1234567890123450000
) in the Excel file if this is not formatted as text.
有什么方法可以在我的 Datatables/TableTools 初始化中设置它,以便它始终将所有数据作为文本导出到 Excel 文件中?
Is there any way I can set this in my Datatables / TableTools initialisation so that it always exports all data as text into the Excel file ?
非常感谢您对此的任何帮助,蒂姆.
Many thanks for any help with this, Tim.
推荐答案
TableTools 不会创建 real excel
文件,它会创建一个 csv
> 文件代替.那些只包含原始数据,没有格式.尽管存在前导零,但 Excel 通常不会显示它们.您有几个选择:
TableTools does not create a real excel
file, it creates a csv
file instead. Those contain only raw data, no formatting. Although the leading zeros are there, Excel usually will not show them. You have several options here:
- 在 Excel 中更改格式
- 从 Excel 的打开对话框中打开
csv
文件,您应该可以从中将列标记为文本(您可能需要将文件类型更改为txt
) - 在数据周围添加引号
- 通过一些外部库创建一个真实 excel 文件
- change the formatting from within Excel
- open the
csv
file from Excel's open dialog, from which you should be able to mark columns as text (you might need to change the file type totxt
) - add quotes around the data
- create a real excel file via some external library
这篇关于Datatables/TableTools:导出到 Excel 时将数据格式化为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!