Imports System.Windows.Forms
Imports FarPoint.Excel
Imports FarPoint.Win.Spread
Imports System.IO
Imports Spread.Common.Features.Spread.Common.Features.Sample

Partial Public Class Introduction
    Inherits BaseSampleControl
    Public Sub New()
        InitializeComponent()
        Name = "Introduction"
        SetupSpreadSheet()
    End Sub
    Private Sub SetupSpreadSheet()
        spread.DefaultSkin = DefaultSpreadSkins.Office2016White
        spread.StatusBarVisible = True
        openResourcesButton_Click(Nothing, EventArgs.Empty)
    End Sub
    Private Sub openButton_Click(sender As Object, e As EventArgs)
        Dim openFileDialog As New OpenFileDialog()
        openFileDialog.Filter = "Excel 97-2007 Workbook(*.xls)|*.xls|Excel Workbook(*.xlsx)|*.xlsx"
        openFileDialog.FilterIndex = 1
        openFileDialog.Multiselect = False
        If openFileDialog.ShowDialog() = DialogResult.OK Then
            Dim _fileName As String = openFileDialog.FileName
            spread.OpenExcel(_fileName)
        End If
    End Sub
    Private Sub saveButton_Click(sender As Object, e As EventArgs)
        Dim _saveFileDialog As New SaveFileDialog()
        _saveFileDialog.Filter = "Excel 97-2007 Workbook(*.xls)|*.xls|Excel Workbook(*.xlsx)|*.xlsx"
        _saveFileDialog.FilterIndex = -1
        If _saveFileDialog.ShowDialog() = DialogResult.OK Then
            Dim _fileName As String = _saveFileDialog.FileName

            spread.SaveExcel(_fileName, (ExcelSaveFlags.UseOOXMLFormat))
        End If
    End Sub
    Private Sub openResourcesButton_Click(sender As Object, e As EventArgs)
        Using s As New MemoryStream(ExcelTemplate.FinancialKPIs)
            spread.OpenExcel(s)
        End Using
    End Sub
End Class

'
'
'

Partial Class Introduction
	''' <summary> 
	''' Required designer variable.
	''' </summary>
	Private components As System.ComponentModel.IContainer = Nothing

    ''' <summary> 
    ''' Clean up any resources being used.
    ''' </summary>
    ''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    Protected Shadows Sub Dispose(disposing As Boolean)
        If disposing AndAlso (components IsNot Nothing) Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

#Region "Component Designer generated code"

    ''' <summary> 
    ''' Required method for Designer support - do not modify 
    ''' the contents of this method with the code editor.
    ''' </summary>
    Private Sub InitializeComponent()
		Me.openButton = New System.Windows.Forms.Button()
		Me.openResourcesButton = New System.Windows.Forms.Button()
		Me.saveButton = New System.Windows.Forms.Button()
		Me.spread = New FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None)
		Me.sheetView = New FarPoint.Win.Spread.SheetView()
		Me.pnlMain.SuspendLayout()
		Me.pnlControls.SuspendLayout()
		DirectCast(Me.spread, System.ComponentModel.ISupportInitialize).BeginInit()
		DirectCast(Me.sheetView, System.ComponentModel.ISupportInitialize).BeginInit()
		Me.SuspendLayout()
		' 
		' pnlMain
		' 
		Me.pnlMain.Controls.Add(Me.spread)
		' 
		' pnlControls
		' 
		Me.pnlControls.Controls.Add(Me.saveButton)
		Me.pnlControls.Controls.Add(Me.openButton)
		Me.pnlControls.Controls.Add(Me.openResourcesButton)
		' 
		' openButton
		' 
		Me.openButton.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.openButton.Location = New System.Drawing.Point(17, 15)
		Me.openButton.Name = "openButton"
		Me.openButton.Size = New System.Drawing.Size(108, 23)
		Me.openButton.TabIndex = 0
		Me.openButton.Text = "Open"
		Me.openButton.UseVisualStyleBackColor = True
		AddHandler Me.openButton.Click, New System.EventHandler(AddressOf Me.openButton_Click)
		' 
		' saveButton
		' 
		Me.saveButton.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.saveButton.Location = New System.Drawing.Point(17, 54)
		Me.saveButton.Name = "saveButton"
		Me.saveButton.Size = New System.Drawing.Size(108, 23)
		Me.saveButton.TabIndex = 1
		Me.saveButton.Text = "Save"
		Me.saveButton.UseVisualStyleBackColor = True
		AddHandler Me.saveButton.Click, New System.EventHandler(AddressOf Me.saveButton_Click)
		' 
		' openResourcesButton
		' 
		Me.openResourcesButton.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.openResourcesButton.Location = New System.Drawing.Point(17, 95)
		Me.openResourcesButton.Name = "openResourcesButton"
		Me.openResourcesButton.Size = New System.Drawing.Size(108, 23)
		Me.openResourcesButton.TabIndex = 0
		Me.openResourcesButton.Text = "Open From Resources"
		Me.openResourcesButton.UseVisualStyleBackColor = True
		AddHandler Me.openResourcesButton.Click, New System.EventHandler(AddressOf Me.openResourcesButton_Click)
		' 
		' spread
		' 
		Me.spread.Dock = System.Windows.Forms.DockStyle.Fill
		Me.spread.Location = New System.Drawing.Point(0, 0)
		Me.spread.Name = "spread"
		Me.spread.Sheets.AddRange(New FarPoint.Win.Spread.SheetView() {Me.sheetView})
		Me.spread.Size = New System.Drawing.Size(477, 487)
		Me.spread.TabIndex = 0
		' 
		' sheetView
		' 
		Me.sheetView.Reset()
		Me.sheetView.SheetName = "Introduction"
		' Formulas and custom names must be loaded with R1C1 reference style
		Me.sheetView.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1
		Me.sheetView.RowHeader.Columns.[Default].Width = 35F
		Me.sheetView.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1
		' 
		' Introduction
		' 
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 13F)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.Name = "Introduction"
		Me.pnlMain.ResumeLayout(False)
		Me.pnlControls.ResumeLayout(False)
		DirectCast(Me.spread, System.ComponentModel.ISupportInitialize).EndInit()
		DirectCast(Me.sheetView, System.ComponentModel.ISupportInitialize).EndInit()
		Me.ResumeLayout(False)

	End Sub

	#End Region
	Private saveButton As System.Windows.Forms.Button
	Private openButton As System.Windows.Forms.Button
	Private openResourcesButton As System.Windows.Forms.Button
	Private spread As FarPoint.Win.Spread.FpSpread
	Private sheetView As FarPoint.Win.Spread.SheetView
End Class
