Results 1 to 5 of 5

Thread: VB.NET to VC#

  1. #1

    Thread Starter
    Hyperactive Member Dorothy's Avatar
    Join Date
    Feb 2001
    Posts
    310

    Question VB.NET to VC#

    Dim a As New Excel.Application()
    Dim wb As Excel.Workbook
    Dim ws As Excel.Worksheet

    wb = a.Workbooks.Open("C:\book1.xls")

    ws = wb.Worksheets.Item(1)

    With ws
    'populate titles
    .Cells(1, 1).value = "Date"
    .Cells(1, 2).value = "Location"

    .Cells(2, 1).value = YOUR STRING VALUE
    .Cells(2, 2).value = YOUR STRING VALUE

    I need the above code converted to VC#. Can anyone help me with this?

  2. #2
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    I cant really test it now but this is the conversion

    static void main
    {
    Excel.Application a = new Excel.Application;
    Excel.Workbook wb = a.Open("C:\book1.xls");
    Excel.Worksheet ws = wb.Worksheets.Item(1);

    ws.Cells(2, 1).value = "YOUR STRING VALUE";
    ws.Cells(2, 2).value = "YOUR STRING VALUE";
    }

    hth
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

  3. #3

    Thread Starter
    Hyperactive Member Dorothy's Avatar
    Join Date
    Feb 2001
    Posts
    310
    Excel.Application a = new Excel.Application;
    Excel.Workbook wb = a.Open ("C:\book1.xls");
    Excel.Worksheet ws = wb.Worksheets.Item (1);

    ws. Cells (2, 1).value = "YOUR STRING VALUE";
    ws. Cells( 2, 2).value = "YOUR STRING VALUE";

    I get error on the underlined codes.

  4. #4
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    What is the error and did you set a reference to the excel runtime library ?
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

  5. #5
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    +++++++++++++
    Excel.Application a = new Excel.Application;
    Excel.Workbook wb = a.Open ("C:\book1.xls");
    Excel.Worksheet ws = wb.Worksheets.Item (1);

    ws. Cells (2, 1).value = "YOUR STRING VALUE";
    ws. Cells( 2, 2).value = "YOUR STRING VALUE";

    I get error on the underlined codes.
    +++++++++++++

    Try this
    =========================
    Excel.Application a = new Excel.Application;
    Excel.Workbook wb = a.Workbooks.Open (@"C:\book1.xls");
    Excel.Worksheet ws = wb.Worksheets.Item [1];

    ws.Range("A1").value = "YOUR STRING VALUE";
    =========================

    Like I said, I dont have a C# compiler to test it right now. If this still doesnt work, post this code snippet in the C# forum and ask for help there
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width