简体   繁体   English

C#-从字符串中粘贴多行单元格以使其表现出色

[英]C# - Paste multiline cells to excel from a string

I was trying copying a string to an excel line using "\\r" to separate the cells. 我试图使用“ \\ r”将字符串复制到excel行中以分隔单元格。 I want only 2 cells to be multiline but using "\\n" will switch the text over to the next line in the spreadsheet instead of making a new line in the cell. 我只希望2个单元格为多行,但是使用“ \\ n”会将文本切换到电子表格的下一行,而不是在单元格中添加新行。 (The program automaticly copies the text to the Clipboard) (程序自动将文本复制到剪贴板)

Is there any way to achieve this? 有什么办法可以做到这一点?

For example if you have a string: 例如,如果您有一个字符串:

    string s = "cell1 \t cell2 \t cell3 \n stillcell3 \t cell4";

It will result in (cell(contents)): A1(cell1) A2(cell2) A3(cell3 newline stillcell3) A4(cell4) 它将导致(cell(contents)):A1(cell1)A2(cell2)A3(cell3 newline stillcell3)A4(cell4)

I hope it made sense and it would be great if you could help me! 我希望这很有道理,如果您能帮助我,那将是很棒的!

Solution: Make sure you have enclosed the multiline section in \\"\\" . 解决方案:确保将多行部分包含在\\"\\"

Try this: 尝试这个:

String s = "cell1\tcell2\t\"cell3\nstillcell3\"\tcell4\r\n";
Clipboard.SetText(s);

Now go to Excel and Paste 现在转到Excel和粘贴

(Control + V)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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