EXCEL Hello World in C#, VB.NET

  • Demo
  • C# source
  • VB.Net source

The sample demonstrates how to write a string to an excel workbook.
HelloWorld.gif

private void btnRun_Click(object sender, System.EventArgs e)
{
       //Creates workbook
       Workbook workbook = new Workbook();
       //Gets first worksheet
       Worksheet sheet = workbook.Worksheets[0];
        
       //Writes hello world to A1
       sheet.Range["A1"].Text = "Hello,World!";

       //Save workbook to disk
       workbook.SaveToFile("Sample.xls");

       //View excel file
       ExcelDocViewer(workbook.FileName);
}

private void ExcelDocViewer( string fileName )
{   
       try   
       {    
          System.Diagnostics.Process.Start(fileName);   
       }   catch{}
}

   Private  Sub ExcelDocViewer(ByVal fileName As String)
      Try
        System.Diagnostics.Process.Start(fileName)
      Catch
      End Try
    End Sub

    Private Sub btnRun_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRun.Click
      'Creates workbook
      Dim workbook As Workbook = New Workbook()
      'Gets first worksheet
      Dim sheet As Worksheet = workbook.Worksheets(0)

      'Writes hello world to A1
      sheet.Range("A1").Text = "Hello,World!"

      'Save workbook to disk
      workbook.SaveToFile("Sample.xls")

      'View excel file
      ExcelDocViewer(workbook.FileName)
    End Sub

    Private Sub btnAbout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAbout.Click
      Close()
    End Sub