in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Formatting cell as text

Last post 12-12-2007 1:14 AM by C1_JohnAd. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 11-13-2007 9:51 AM

    • Joel
    • Not Ranked
    • Joined on 04-03-2006
    • Posts 1

    Formatting cell as text

    I'm using C1 XLS to create Excel files from datasets in an ASP.NET web application. One problem I'm running into is a format issue with text that looks like numbers to Excel. For example, US Postal codes that begin with zero such as 01234 end up in Excel as 1234. Working in Excel, I would solve that issue by formatting the cell as text or by adding a single quote to the cell text ('01234).

     How can I achieve the same results with C1 XLS? I've looked at FormatDotNetToXL but the documentation is not helpful. (No examples at all for one thing).

     

  • 12-12-2007 1:14 AM In reply to

    Re: Formatting cell as text

    Hello ,

    With reference to your query I would like to mention that the behavior you
    are experiencing is the default behavior. However, you may use the
    following code snippet to do this.


    BEGIN CODE

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles button1.Click

    ' step 1: create a new workbook
    Dim book As C1XLBook = New C1XLBook()

    ' step 2: get the sheet that was created by default, give it a name
    Dim sheet As XLSheet = book.Sheets(0)
    sheet.Name = "Hello World"

    ' step 3: create styles for odd and even values
    Dim styleOdd As XLStyle = New XLStyle(book)
    styleOdd.Font = New Font("Tahoma", 9, FontStyle.Italic)
    styleOdd.ForeColor = Color.Blue
    Dim styleEven As XLStyle = New XLStyle(book)
    styleEven.Font = New Font("Tahoma", 9, FontStyle.Bold)
    styleEven.ForeColor = Color.Red

    ' step 3: write content and format into some cells
    Dim i As Integer
    For i = 0 To 99

    Dim cell As XLCell = sheet(i, 0)
    cell.Value = "'0" + CStr(i + 1)
    cell.Style = IIf(((i + 1) Mod 2 = 0), styleEven, styleOdd)
    Next

    ' step 4: save the file
    Dim fileName As String = Application.StartupPath + "\hello.xls"
    book.Save(fileName)
    System.Diagnostics.Process.Start(fileName)

    End Sub

    END CODE

    I hope this helps.

    Regards,
    John Adams
    Technical Support, ComponentOne LLC

    wrote in message news:199661@10.0.1.98...
    I'm using C1 XLS to create Excel files from datasets in an ASP.NET web
    application. One problem I'm running into is a format issue with text that
    looks like numbers to Excel. For example, US Postal codes that begin with
    zero such as 01234 end up in Excel as 1234. Working in Excel, I would solve
    that issue by formatting the cell as text or by adding a single quote to the
    cell text ('01234).
    How can I achieve the same results with C1 XLS? I've looked at
    FormatDotNetToXL but the documentation is not helpful. (No examples at all
    for one thing).




    http://helpcentral.componentone.com/cs/forums/p/73547/199661.aspx#199661
Page 1 of 1 (2 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.