0

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?

Farzad J
  • 1,089
  • 2
  • 14
  • 28

2 Answers2

0

I'm afraid Clipboard is too simple tool for the job. If I were you I would concider using Open XML library.

  • Thanks Michal , is it (Open xml Library) going to use ctrl+v to past information into excel or it's going to build a new excel file ? – Farzad J Feb 19 '14 at 12:19
  • Open XML enables you to open, edit and save Excel (and many other) files. You can find some samples [here](http://stackoverflow.com/a/17207324/2404858) and [here](http://stackoverflow.com/a/5220844/2404858) – michal.pawlowski Feb 19 '14 at 13:58
0

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

Community
  • 1
  • 1
Steve
  • 976
  • 5
  • 15