0

I have button in my c# application that should format and copy data from few sources.

And i have a problem to paste my text from clipboard to excel.

In excel all text like 1.12.1 is transfromed to 01.12.2001 datetime format! And i dont want to do like that!

foreach (var data in collection)
{
  sb.Append(data.Column1+ "\t");
  sb.Append(data.Column2+ "\t");
  sb.Append(data.Column33+ "\t");

  sb.AppendLine();
}

var clipboardResults = new DataObject();
clipboardResults.SetData(DataFormats.Text, sb.ToString());
Clipboard.SetDataObject(clipboardResults);

Is it possible to format my text so excel will understand that copied data is text and not date time!

Ievgen
  • 4,261
  • 7
  • 75
  • 124

2 Answers2

2

In the Excel document where you are going to paste the data, you need to select and set the format of the destination cells as Text. It will prevent Excel from trying to interpret the data when you paste it.

To avoid doing that, you can try using the XML Spreadsheet Format: C# Add excel text-formatted data to clipboard

Community
  • 1
  • 1
Maxime Biette
  • 303
  • 2
  • 5
1

Did you try putting the text identifier (single quote) in front of it?

e.g. '1.12.1

Kevin
  • 2,566
  • 1
  • 11
  • 12
  • But than value in cell will be also '1.12.1 But is it possible to paste text like it is 1.12.1 and not datetime! – Ievgen Sep 15 '13 at 13:47