Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. could I write text in two or three lines to a cell with VB.NET?

could I write text in two or three lines to a cell with VB.NET?

Scheduled Pinned Locked Moved Visual Basic
questioncsharphelp
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sanyexian
    wrote on last edited by
    #1

    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!

    L S D 3 Replies Last reply
    0
    • S sanyexian

      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!

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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.

      S 1 Reply Last reply
      0
      • S sanyexian

        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!

        S Offline
        S Offline
        Sonhospa
        wrote on last edited by
        #3

        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.

        S 1 Reply Last reply
        0
        • S Sonhospa

          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.

          S Offline
          S Offline
          sanyexian
          wrote on last edited by
          #4

          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!

          S 1 Reply Last reply
          0
          • L Luc Pattyn

            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.

            S Offline
            S Offline
            sanyexian
            wrote on last edited by
            #5

            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!

            L 1 Reply Last reply
            0
            • S sanyexian

              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!

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • S sanyexian

                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!

                D Offline
                D Offline
                DaveAuld
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • S sanyexian

                  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!

                  S Offline
                  S Offline
                  Sonhospa
                  wrote on last edited by
                  #8

                  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 ;)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups