简体   繁体   English

有什么方法可以通过编程方式将 Excel 单元格保存到本地文件,这些文件可以像使用 VSTO 的“复制和粘贴”一样加载?

[英]Is there any way to programaticallly save Excel cell to local files that could be load just like "copy and paste" with VSTO?

I've been working with Excel VSTO Add-in these days, and what I need is to load some templates from the database, and fill them in the Excel cells.这些天我一直在使用Excel VSTO Add-in,我需要的是从数据库中加载一些模板,并将它们填充到Excel单元格中。

The thing is I can only store the data in plain text, the style and format would be missing if I try to copy and paste a target cell and store it somewhere in the notepads (or other editors).问题是我只能以纯文本格式存储数据,如果我尝试复制并粘贴目标单元格并将其存储在记事本(或其他编辑器)中的某个位置,样式和格式就会丢失。

Is there any way to save the cell data with styles to some binary local file (or others), and when I need it sometime, I could load and fill it to a targeted cell, like I have just copied it from some cells else.有什么方法可以将带有 styles 的单元格数据保存到某个二进制本地文件(或其他文件)中,当我需要它的时候,我可以将它加载并填充到目标单元格,就像我刚刚从其他单元格复制它一样。

Thanks!谢谢!

PS: the text might have different styles so the storage of cell's formats might not work, PS:文本可能有不同的 styles 所以单元格格式的存储可能不起作用,

I've attached an example here:我在这里附上了一个例子:

例子

I finally solved it with我终于解决了

Range.Value[XlRangeValueDataType.xlRangeValueXMLSpreadsheet] Range.Value[XlRangeValueDataType.xlRangeValueXMLSpreadsheet]

It stores the cell as XML, with all the styles I need.它将单元格存储为 XML,以及我需要的所有 styles。

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

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