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!

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

e.g. '1.12.1

1 Comment

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.