[英]How do I set a text in clipboard using C# in order to past it into excel with different background/font color for each cell?
I follow the below pattern and I can easily copy text into clipboard in order to past it later on into excel, but now I like to have different background/font color for each cell. 我遵循以下模式,可以轻松地将文本复制到剪贴板中,以便稍后将其粘贴到excel中,但是现在我希望每个单元格具有不同的背景/字体颜色。
When copying the data to clipboard, format it as Tab separated for columns, and Enter separated for rows. 将数据复制到剪贴板时,将其格式化为Tab分隔的列,按Enter分隔的行。 When pasting in Excel it will automatically put the values in rows and columns.
在Excel中粘贴时,它将自动在行和列中放置值。
example of my code : 我的代码示例:
string clipboardText = "cell11" + "\t" + "cell12" + "\r\n" + "cell21" + "\t" + "cell22";
Clipboard.SetText(clipboardText);
any idea how to set a background/font color for each cell? 任何想法如何为每个单元格设置背景/字体颜色?
I'm afraid Clipboard is too simple tool for the job. 恐怕剪贴板对于这项工作来说太简单了。 If I were you I would concider using Open XML library .
如果我是你,我会考虑使用Open XML库 。
You can write your own copy function and use html to pass colour and font information. 您可以编写自己的复制功能,并使用html传递颜色和字体信息。 See this question .
看到这个问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.