Program Guide (1)
How to Open and View Excel in Windows Form using Spire.Speadsheet
2016-04-19 03:20:45 Written by support iceblueSpire.Spreadsheet is a .NET Excel viewer control that allows programmers to load Excel spreadsheet in Windows form, manipulate the data in it and save to file. This guide will introduce how to add Spire.Spreadsheet controls to Toolbox and how to create a Windows Form Application to display Excel spreadsheet.
Add Spire.Spreadsheet Controls to Toolbox
Right-click on the white space of the Toolbox – "Add Tab" - name the new Tab "Spire.Spreadsheet Controls":
Right-click on the blank part below "Spire.Spreadsheet Controls" - "Choose Items" - ".NET Framework Components" - "Browse" to the "Bin" folder - find the file "Spire.Spreadsheet.dll" - "Open".
Click "OK". Then you have added controls to Toolbox successfully.
Create a Windows Form Application to Display Spreadsheet
Create a Windows Form Application, drag Spreadsheet control to form1 and add an openToolStrip in menuStrip to open an Excel file.
Double click openToolStrip to write code. The spreadsheet1 that represents Spreadsheet control can easily load an Excel file by LoadFromFile() method.
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofDialog = new OpenFileDialog(); ofDialog.Filter = "All files|*.*|Microsoft Excel Files(*.xls;*.xlsx;*.ods;*.xlsb)|*.xls;*.xlsx;*.xlsb;*.ods"; if (ofDialog.ShowDialog() == DialogResult.OK) spreadsheet1.LoadFromFile(ofDialog.FileName); }
Run the program and open an existing Excel file, you’ll get following output: