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. 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?
任何想法如何设置每个单元格的背景/字体颜色?
2 个解决方案
#1
0
I'm afraid Clipboard is too simple tool for the job. If I were you I would concider using Open XML library.
我担心剪贴板是一个太简单的工具。如果我是你,我会使用Open XML库来调整。
#2
0
You can write your own copy function and use html to pass colour and font information. See this question.
您可以编写自己的复制功能并使用html传递颜色和字体信息。看到这个问题。
#1
0
I'm afraid Clipboard is too simple tool for the job. If I were you I would concider using Open XML library.
我担心剪贴板是一个太简单的工具。如果我是你,我会使用Open XML库来调整。
#2
0
You can write your own copy function and use html to pass colour and font information. See this question.
您可以编写自己的复制功能并使用html传递颜色和字体信息。看到这个问题。