You can use the Excel Import and Export Component to import and export Excel files into the SpreadJS widget. The component resides on your application server. This example shows how to use the Excel Import and Export component in a Visual Studio 2015 Windows Forms application. Use the following steps to create the sample:
Add import and export logic in the two button click events. For example: C#
using GrapeCity.Spread.Sheets.ExcelIO;
using GrapeCity.Windows.SpreadSheet.Data;
using System;
using System.IO;
using System.Windows.Forms;
private void Import_Click(object sender, EventArgs e)
{
DialogResult result = this.openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
using (Stream stream = File.Open(this.openFileDialog1.FileName, FileMode.Open))
{
Importer importer = new Importer();
this.richTextBox1.Text = importer.ImportExcel(stream);
}
}
}
private void Export_Click(object sender, EventArgs e)
{
DialogResult result = this.saveFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
using (FileStream fs = File.Create(this.saveFileDialog1.FileName))
{
Exporter exporter = new Exporter(this.resultRtb.Text);
exporter.SaveExcel(fs, ExcelFileFormat.XLSX, ExcelSaveFlags.NoFlagsSet); }
}
}
VB
Imports GrapeCity.Spread.Sheets.ExcelIO
Imports GrapeCity.Windows.SpreadSheet.Data
Imports System
Imports System.IO
Imports System.Windows.Forms
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Import_Click(sender As Object, e As EventArgs) Handles Import.Click
Dim result As DialogResult = Me.OpenFileDialog1.ShowDialog()
If result = DialogResult.OK Then
Using stream As Stream = File.Open(Me.OpenFileDialog1.FileName, FileMode.Open)
Dim importer As New Importer()
Me.RichTextBox1.Text = importer.ImportExcel(stream)
End Using
End If
End Sub
Private Sub Export_Click(sender As Object, e As EventArgs) Handles Export.Click
Dim result As DialogResult = Me.SaveFileDialog1.ShowDialog()
If result = DialogResult.OK Then
Using fs As FileStream = File.Create(Me.SaveFileDialog1.FileName)
Dim exporter As New Exporter(Me.RichTextBox1.Text)
exporter.SaveExcel(fs, ExcelFileFormat.XLSX, ExcelSaveFlags.NoFlagsSet)
End Using
End If
End Sub
End Class
Build and Press F5 to run. Select the Import Excel button to import an Excel-formatted file.