could I write text in two or three lines to a cell with VB.NET?
-
Hi,everyone,now I need to write some texts to some cells with VB.NET ,sometimes I need the texts wrote in two lines or three lines in one cell.Just like below: "ABCDEFG" ,in the cell it should like ABC DEFG That is the question:could I control it with VB.NET? Need some help or sugestion,Thanks a lot!
-
Hi,everyone,now I need to write some texts to some cells with VB.NET ,sometimes I need the texts wrote in two lines or three lines in one cell.Just like below: "ABCDEFG" ,in the cell it should like ABC DEFG That is the question:could I control it with VB.NET? Need some help or sugestion,Thanks a lot!
you did not say on what surface, in what Control, where at all this is going on. Some Controls simply accept multi-line text and perform wrapping themselves; most of those also understand Environment.NewLine; some have a property you'd have to set true before they accept multi-line text; and some don't at all. PS: all of them would tell you in the documentation, all it takes is to go to the appropriate page; I can't provide a link as I'm in the dark of the very nature of your cells. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
-
Hi,everyone,now I need to write some texts to some cells with VB.NET ,sometimes I need the texts wrote in two lines or three lines in one cell.Just like below: "ABCDEFG" ,in the cell it should like ABC DEFG That is the question:could I control it with VB.NET? Need some help or sugestion,Thanks a lot!
Since you're speaking about cells without additonal information I assume you might mean Excel cells. In that case I'd suggest to use VBA, which is integrated into Excel. Using VB.NET wouldn't make a lot of sense. Maybe you let us know more, we're only guessing here.
-
Since you're speaking about cells without additonal information I assume you might mean Excel cells. In that case I'd suggest to use VBA, which is integrated into Excel. Using VB.NET wouldn't make a lot of sense. Maybe you let us know more, we're only guessing here.
-
you did not say on what surface, in what Control, where at all this is going on. Some Controls simply accept multi-line text and perform wrapping themselves; most of those also understand Environment.NewLine; some have a property you'd have to set true before they accept multi-line text; and some don't at all. PS: all of them would tell you in the documentation, all it takes is to go to the appropriate page; I can't provide a link as I'm in the dark of the very nature of your cells. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
-
I feel very very sorry for my carelessness that made you perplexed.What I wanted to say was "EXCEL cells" and the text came from some VB.NET controls such as TEXTBOX or COMBOBOX. Luc,could you give me some suggestion now?THX!
I haven't done this myself, however I think "abc\ndef" will show as two lines in a single Excel cell if the cell formatting allows wrapping. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
-
Hi,everyone,now I need to write some texts to some cells with VB.NET ,sometimes I need the texts wrote in two lines or three lines in one cell.Just like below: "ABCDEFG" ,in the cell it should like ABC DEFG That is the question:could I control it with VB.NET? Need some help or sugestion,Thanks a lot!
While working in excel directly not via code, you can use ALT+Enter keystroke to achieve this. While using code it is as simple as inserting a Carriage Return and Line feed into the string.
Private Sub doSomething()
Dim xlApp As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application() Dim xlWk As Microsoft.Office.Interop.Excel.Workbook = xlApp.Workbooks.Add() Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet = xlWk.Worksheets(1) xlApp.Visible = True xlSheet.Range("A1").Value = "Some Text Value on 1 line" xlSheet.Range("A5").Value = "Some text value on" + vbCrLf + "2 lines" xlSheet.Columns().AutoFit() xlSheet.Rows().AutoFit() End Sub
Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn
Waving? dave.m.auld[at]googlewave.com -
oh,I'm very very sorry for my carelessly! What I really want to say was "EXCEL CELLS"… It seams that the problem only could be done with VBA…Em…I will try it .Thank you!
Hi, Dave's (the next) answer is exactly what I would have suggested. Still I don't understand when you say the text comes from VB.NET controls - would that mean you would first have to grab the text from a different program? In that case it's a much (muchmuch!) harder job to do, so I hope I'm misinterpreting that remark ;-). If you wanted to say "VBA controls" instead (i.e. inside Excel) then again it's something you can manage without going insane ;)