简体   繁体   English

C#-如何在当前工作簿中保存一个Excel WorkSheet?

[英]C# - How to save a single Excel WorkSheet in the current WorkBook?

I have seen some other existing questions about saving a single worksheet but the are regarding saving a worksheet in a new workbook (by copying it to the new workbook and then saving it. What I need is to save just one specific worksheet within the existing workbook, is to not possible? 我已经看到了有关保存单个工作表的其他一些现有问题,但是关于将工作表保存在新工作簿中(通过将其复制到新工作簿然后再保存)。我需要的是在现有工作簿中仅保存一个特定工作表,是不可能的吗?

Thank you! 谢谢!

No 没有

If you check the list of Microsoft Office file specifications , none of them accommodate the storage of a single worksheet. 如果您查看Microsoft Office文件规范列表,则它们都不能容纳单个工作表的存储。 So the answer to your question is no. 因此,您的问题的答案是否定的。

Yes

On the other hand, when you save as a non-Excel type such as CSV or TXT , Excel will only save the current sheet. 另一方面,当您另存为CSV或TXT等非Excel类型时 ,Excel将仅保存当前工作表。 So if you're OK with storing the worksheet in a non-native format, with possible data loss, then the answer is yes. 因此,如果您可以将工作表以非本地格式存储(可能会丢失数据),那么答案是肯定的。

If you want to read worksheets programmatically then this might help you. 如果您想以编程方式阅读工作表,则可能会对您有所帮助。

You can programmatically read each sheet in a workbook and save a particular sheet or a range of cells inside the sheet in the same workbook or as new sheet or as .txt,.csv and many other formats.. Use ByteScout and read about the documentation from here . 您可以以编程方式阅读工作簿中的每个工作表,并以同一工作簿或新工作表或.txt,.csv和许多其他格式来保存特定工作表或工作表中的单元格区域 。使用ByteScout并阅读有关文档的信息从这里 There are many examples provided by them. 他们提供了许多示例。 Please let us know if you are facing any problem. 如果您遇到任何问题,请告诉我们。

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

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