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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Using writeline to write string with leading 0's to excel worksheet columns?

Using writeline to write string with leading 0's to excel worksheet columns?

Scheduled Pinned Locked Moved Visual Basic
question
2 Posts 2 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.
  • R Offline
    R Offline
    Rashar
    wrote on last edited by
    #1

    Hi, Consider the following line, oWrite.WriteLine(strItem & vbTab & partNo) The variable partNo is a string that pulls in a number as such, 00001567842. I am using the writeline method to send that string to an excel sheet. I need to have the values in strItem in column 1, and the values of partNo in column 2 including the leading zeros. I have tried the {1,11}, partNo format or Format("###########", partNo). I have tried declairing partNo as a String as well as an Integer, but neither data types work. I tried to create a csv file, and it does include the leading 0's but when I use vtab, I get the values of strItem, plus a square (which I assume is the vtab), then my partNo all in one cell. Is it possible to accomplish what I want with just the WriteLine method? Thanks in advance.

    N 1 Reply Last reply
    0
    • R Rashar

      Hi, Consider the following line, oWrite.WriteLine(strItem & vbTab & partNo) The variable partNo is a string that pulls in a number as such, 00001567842. I am using the writeline method to send that string to an excel sheet. I need to have the values in strItem in column 1, and the values of partNo in column 2 including the leading zeros. I have tried the {1,11}, partNo format or Format("###########", partNo). I have tried declairing partNo as a String as well as an Integer, but neither data types work. I tried to create a csv file, and it does include the leading 0's but when I use vtab, I get the values of strItem, plus a square (which I assume is the vtab), then my partNo all in one cell. Is it possible to accomplish what I want with just the WriteLine method? Thanks in advance.

      N Offline
      N Offline
      ne0h
      wrote on last edited by
      #2

      Change the Cell's property to Text. I think you need to create an object of Microsoft.Office.Interop.Excel.Style then use NuberFormat property. Just Google it. By default Excel cells are Number type.

      -------------------------------- txtSignature

      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