简体   繁体   中英

New line character in excel when printing from vb.net

I am trying to print a value to a cell that contains a line seperator like ALT + ENTER or Char(10) . Everything so far just prints my text so that it prints the values I want to wrap in the excel are in different cells

In my vb.net code I keep building a string as I loop through reports and I have tried vbcrlf , vblf etc to try and mimic a ALT + ENTER entry in excel using something similar to the below

_string = _string & vbcrlf & report.name &" " & _pctstatus &"%"

and then I paste this string into A1 using

Clipboard.SetDataObject(_string.ToString, False)
aRange.Select()
aWorkSheet.Paste()

In the picture you can see I keep getting the values in A3 but I really want the result in A1

Excel输出

I can get around this by structuring my text as formula so that Char(10) is in the cell formula but I would prefer just enter a string value and have no formulae. I also have to do this as I am constrained by the number of free cells in the excel report since I am adding this an excel sheet heavily populated already

So is any special need to use clipboard? If not try this:

aRange.Value = _string.ToString

单元格的格式是否设置为允许多行(自动换行)?

只需使用vbLf而不是vbCrLf

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