简体   繁体   English

c#导出CSV文件隐藏列

[英]c# Export CSV File Hide Columns

I am using HttpContext to export a data table to a CSV file which will be used in excel for people to look at. 我正在使用HttpContext将数据表导出到CSV文件,该文件将在excel中供人们查看。 This very same file will later be imported and parsed to get values inserted and such. 稍后将导入和解析此文件,以获取插入的值等等。 However there are some columns that need to be hidden in the final excel export but still need to be recognized when importing the file. 但是,有些列在最终的excel导出中需要隐藏,但在导入文件时仍需要识别。 So essentially when looking at the file through excel, people should not see the hidden columns, but they should be there and readable when parsing the file back. 因此,从本质上讲,当通过excel查看文件时,人们不应看到隐藏的列,但在解析文件时它们应该在那里并且可读。 Is there a property that I need to set to make this happen? 是否需要设置属性才能实现此目的?

This is not possible with the .CSV file format. .CSV文件格式不可行。 It does not support flagging columns as invisible and excel will not, by default, hide any columns when you open a .csv file with it. 它不支持标记列,因为默认情况下,当您使用.csv文件打开它时,excel不会隐藏任何列。

You would need a custom excel template/plugin and custom logic to detect and hide certain columns. 您将需要一个自定义excel模板/插件和自定义逻辑来检测和隐藏某些列。

My recomendation is that you do not go this way. 我的建议是您不要这样走。 Choose a different export / edit strategy. 选择其他导出/编辑策略。 If excel is a must, switch to exporting full excel documents where you can then customize the columns and define how and when they can be edited. 如果必须使用excel,请切换到导出完整的excel文档,然后在其中自定义列并定义如何以及何时进行编辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM