Sample source codes below will show you how to cope with a difficult task, for example, calculations and spreadsheet as database in VB.NET. ByteScout Spreadsheet SDK was made to help with calculations and spreadsheet as database in VB.NET. ByteScout Spreadsheet SDK is the SDK to create, read, modify and calculate spreadsheets. Formula calculations are supported, import and export to and from JSON, CSV, XML, databases, arrays.
VB.NET code snippet like this for ByteScout Spreadsheet SDK works best when you need to quickly implement calculations and spreadsheet as database in your VB.NET application. This VB.NET sample code should be copied and pasted into your application’s code editor. Then just compile and run it to see how it works. Further enhancement of the code will make it more vigorous.
ByteScout Spreadsheet SDK free trial version is available for download from our website. Free trial also includes programming tutorials along with source code samples.
On-demand (REST Web API) version:
Web API (on-demand version)
On-premise offline SDK for Windows:
60 Day Free Trial (on-premise)
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Button4 = New System.Windows.Forms.Button
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Label5 = New System.Windows.Forms.Label
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.Button4)
Me.GroupBox1.Controls.Add(Me.TextBox4)
Me.GroupBox1.Controls.Add(Me.Label3)
Me.GroupBox1.Controls.Add(Me.TextBox3)
Me.GroupBox1.Controls.Add(Me.Label4)
Me.GroupBox1.Controls.Add(Me.TextBox2)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.TextBox1)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Location = New System.Drawing.Point(12, 6)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(166, 212)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
'
'Button4
'
Me.Button4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
Me.Button4.Location = New System.Drawing.Point(9, 175)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(135, 23)
Me.Button4.TabIndex = 14
Me.Button4.Text = "Recalculate"
Me.Button4.UseVisualStyleBackColor = True
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(9, 149)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(135, 20)
Me.TextBox4.TabIndex = 13
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(6, 94)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(39, 13)
Me.Label3.TabIndex = 12
Me.Label3.Text = "Label3"
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(9, 110)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(135, 20)
Me.TextBox3.TabIndex = 11
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(6, 133)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(39, 13)
Me.Label4.TabIndex = 10
Me.Label4.Text = "Label4"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(9, 71)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(135, 20)
Me.TextBox2.TabIndex = 9
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(6, 55)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(39, 13)
Me.Label2.TabIndex = 8
Me.Label2.Text = "Label2"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(9, 32)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(135, 20)
Me.TextBox1.TabIndex = 7
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(6, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(39, 13)
Me.Label1.TabIndex = 6
Me.Label1.Text = "Label1"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(184, 12)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(100, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Load from XLS"
Me.Button1.UseVisualStyleBackColor = True
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(184, 41)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(100, 23)
Me.Button2.TabIndex = 2
Me.Button2.Text = "Save to XLS"
Me.Button2.UseVisualStyleBackColor = True
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(184, 70)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(100, 23)
Me.Button3.TabIndex = 3
Me.Button3.Text = "View in Excel"
Me.Button3.UseVisualStyleBackColor = True
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(9, 236)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(275, 113)
Me.Label5.TabIndex = 4
Me.Label5.Text = resources.GetString("Label5.Text")
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(294, 372)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.GroupBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Simple Database"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)
End Sub
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Label5 As System.Windows.Forms.Label
End Class
60 Day Free Trial or Visit ByteScout Spreadsheet SDK Home Page
Explore ByteScout Spreadsheet SDK Documentation
Explore Samples
Sign Up for ByteScout Spreadsheet SDK Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
Imports Bytescout.Spreadsheet
Imports System.Diagnostics
Public Class Form1
Dim _spreadsheet As Spreadsheet
Private Sub LoadXLS()
Dim worksheet As Worksheet
_spreadsheet = New Spreadsheet()
_spreadsheet.LoadFromFile("Database.xls")
worksheet = _spreadsheet.WorkBook.Worksheets(0)
Label1.Text = worksheet.Cell("A1").Value
TextBox1.Text = worksheet.Cell("A2").Value
Label2.Text = worksheet.Cell("B1").Value
TextBox2.Text = worksheet.Cell("B2").Value
Label3.Text = worksheet.Cell("C1").Value
TextBox3.Text = worksheet.Cell("C2").Formula
Label4.Text = "Calculated value of C2"
worksheet.Cell("C2").Calculate()
TextBox4.Text = worksheet.Cell("C2").Value
End Sub
Private Sub SaveXLS()
Dim worksheet As Worksheet
worksheet = _spreadsheet.WorkBook.Worksheets(0)
worksheet.Cell("A2").Value = System.Convert.ToInt32(TextBox1.Text)
worksheet.Cell("B2").Value = System.Convert.ToInt32(TextBox2.Text)
worksheet.Cell("C2").Formula = TextBox3.Text
Try
System.IO.File.Delete("Database.xls")
Catch ex As Exception
End Try
_spreadsheet.SaveAs("Database.xls")
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
SaveXLS()
_spreadsheet.Close()
End Sub
Private Sub ReCalculate()
Dim worksheet As Worksheet
worksheet = _spreadsheet.Workbook.Worksheets(0)
worksheet.Cell("A2").Value = System.Convert.ToInt32(TextBox1.Text)
worksheet.Cell("B2").Value = System.Convert.ToInt32(TextBox2.Text)
worksheet.Cell("C2").Formula = TextBox3.Text
worksheet.Cell("C2").Calculate()
TextBox4.Text = worksheet.Cell("C2").Value
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
ReCalculate()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadXLS()
End Sub
Private Sub TextBox_Recalculate(ByVal sender As System.Object, ByVal e As System.EventArgs)
ReCalculate()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
' open in default spreadsheets viewer/editor
SaveXLS()
Try
Process.Start("Database.xls")
Catch
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
LoadXLS()
MessageBox.Show("Loaded from Database.xls")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SaveXLS()
MessageBox.Show("Saved into Database.xls")
End Sub
End Class
60 Day Free Trial or Visit ByteScout Spreadsheet SDK Home Page
Explore ByteScout Spreadsheet SDK Documentation
Explore Samples
Sign Up for ByteScout Spreadsheet SDK Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples
60 Day Free Trial or Visit ByteScout Spreadsheet SDK Home Page
Explore ByteScout Spreadsheet SDK Documentation
Explore Samples
Sign Up for ByteScout Spreadsheet SDK Online Training
Get Your API Key
Explore Web API Docs
Explore Web API Samples