Tag Archives: Excel

Load a CSV file in Excel in C#

Loading a CSV file (comma-separated value file) into Excel isn’t too hard once you know the tricks. Using the same tricks you can load a file that uses any delimiter, not just a comma. First at design time, add a … Continue reading

Posted in Excel, files, Office | Tagged , , , , , , , , , , , , | 5 Comments

Make an Excel chart in C#

This example uses the following code to create an Excel chart in a new workbook. private void btnCreateChart_Click( object sender, EventArgs e) { // Get the Excel application object. Excel.Application excel_app = new Excel.ApplicationClass(); // Make Excel visible (optional). excel_app.Visible … Continue reading

Posted in Excel, interoperability, Office | Tagged , , , , , , , , , , | 1 Comment

Add and remove pictures in an Excel worksheet

This is another brief foray into VBA programming. When you click the Insert Image button, the following VBA code executes. ‘ Insert a picture at the selection. Sub Button1_Click() Dim filters As String Dim filename As Variant ‘ Define the … Continue reading

Posted in Excel, Office, VBA | Tagged , , , , , , , , , | Leave a comment

Read Excel data in C#

To read Excel data, you can open the Excel application and use it as a server to manipulate Excel workbooks. First open the Add References dialog. On the COM tab, select “Microsoft Excel 14.0 Object Library” (or whatever version you … Continue reading

Posted in Excel, Office | Tagged , , , , , , , , , | 6 Comments

Write Excel data in C#

This example shows how to write Excel data into a workbook. You can do that by opening the Excel application and use it as a server to manipulate Excel workbooks. First open the Add References dialog. On the COM tab, … Continue reading

Posted in Excel, Office | Tagged , , , , , , , , , | 8 Comments

Use VBA code to pick random cells from the currently selected cells in an Excel workbook

This example shows how you can use VBA code to pick random cells in an Excel workbook. Sooner or later, many programmers need to write code to control another application such as the Microsoft Office applications, either for their own … Continue reading

Posted in Excel, VBA | Tagged , , , , , , , , , , | 5 Comments

Convert between Excel column numbers and names in C#

Excel uses both numbers and names to identify columns. A = 1, B = 2, …, Z = 26, AZ = 27, …, XFD = 16,384. This example converts between these Excel-style column numbers and names. It’s a little trickier … Continue reading

Posted in algorithms, Excel, Office | Tagged , , , , , , , , , | 2 Comments