简体   繁体   中英

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.

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.

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 .

You can write your own copy function and use html to pass colour and font information. See this question .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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