简体   繁体   English

如何使用C#在剪贴板中设置文本,以便将每个文本粘贴到具有不同背景/字体颜色的excel中?

[英]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.

相关问题 如何使用c#不填充excel单元格的背景颜色? - How to use no fill for background color of a excel cell using c#? 如何使用C#获取excel的单元格背景颜色? - how to get cell background color of excel using C#? 在 C# 中,如何根据某些条件将导出的 Excel 文件的背景颜色单元格设置为特定颜色? - In C#, how can I set the background color cell of exported Excel file to particular color based on some conditions? 如何在C#中更改Excel工作表单元格的背景颜色 - How to change the background color of an Excel sheet cell in C# 如何使用C#以不同的颜色,大小,字体,粗体和斜体格式以excel或csv格式写入数据 - How to write data in excel or csv with different color, size , Font , Bold and Italic format using c# 如何使用C#在Excel中更改系列颜色? - How to do I change a Series color in Excel using C#? 如何在不使用剪贴板的情况下在C#中保存Excel中的图像? - How do I save images from Excel without using Clipboard, in C#? C#:如何不断检查剪贴板上的复制文本 - C#: How Do I Constantly Check the Clipboard for Copied Text 如何使用C#在RichTextBox中设置文本的颜色? - How can I set the color of text in a richtextbox using c#? 如何使用 C# 动态更改 Excel 单元格颜色 - How to Change Excel Cell Color Dynamically using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM