导出到Excel时将文本格式化为文本

导出到Excel时将文本格式化为文本

本文介绍了Datatables / TableTools:导出到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 ),最后四位数字更改为零(例如 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 ?

非常感谢Tim的任何帮助。

Many thanks for any help with this, Tim.

推荐答案

TableTools不会创建一个真实 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内的格式

  • 打开 csv 文件从Excel的打开对话框,您应该可以标记列为文本(您可能需要将文件类型更改为 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 to txt)
  • add quotes around the data
  • create a real excel file via some external library

这篇关于Datatables / TableTools:导出到Excel时将文本格式化为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 21:37