ByteScout Spreadsheet SDK - C# - Calculations and Spreadsheet as Database - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

ByteScout Spreadsheet SDK – C# – Calculations and Spreadsheet as Database

  • Home
  • /
  • Articles
  • /
  • ByteScout Spreadsheet SDK – C# – Calculations and Spreadsheet as Database

calculations and spreadsheet as database in C# and ByteScout Spreadsheet SDK

calculations and spreadsheet as database in C#

ByteScout tutorials explain the material for programmers who use C#. ByteScout Spreadsheet SDK helps with calculations and spreadsheet as database in C#. ByteScout Spreadsheet SDK is the library (SDK) that is capable of writing, reading, modifying and calculating Excel and CSV spreadsheets. Most popular formulas can be calculated and reculculated with Excel installed. You may import or export data to and from CSV, XML, JSON as well as to and from databases, arrays.

C#, code samples for C#, developers help to speed up the application development and writing a code when using ByteScout Spreadsheet SDK. This C# 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.

Our website provides free trial version of ByteScout Spreadsheet SDK. It comes along with all these source code samples with the goal to help you with your C# application implementation.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

Form1.Designer.cs
      
namespace SimpleDatabase { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.Label3 = new System.Windows.Forms.Label(); this.TextBox3 = new System.Windows.Forms.TextBox(); this.Label4 = new System.Windows.Forms.Label(); this.Button2 = new System.Windows.Forms.Button(); this.Button4 = new System.Windows.Forms.Button(); this.Button1 = new System.Windows.Forms.Button(); this.Button3 = new System.Windows.Forms.Button(); this.TextBox4 = new System.Windows.Forms.TextBox(); this.Label5 = new System.Windows.Forms.Label(); this.TextBox2 = new System.Windows.Forms.TextBox(); this.Label2 = new System.Windows.Forms.Label(); this.GroupBox1 = new System.Windows.Forms.GroupBox(); this.TextBox1 = new System.Windows.Forms.TextBox(); this.Label1 = new System.Windows.Forms.Label(); this.GroupBox1.SuspendLayout(); this.SuspendLayout(); // // Label3 // this.Label3.AutoSize = true; this.Label3.Location = new System.Drawing.Point(6, 94); this.Label3.Name = "Label3"; this.Label3.Size = new System.Drawing.Size(39, 13); this.Label3.TabIndex = 12; this.Label3.Text = "Label3"; // // TextBox3 // this.TextBox3.Location = new System.Drawing.Point(9, 110); this.TextBox3.Name = "TextBox3"; this.TextBox3.Size = new System.Drawing.Size(135, 20); this.TextBox3.TabIndex = 11; // // Label4 // this.Label4.AutoSize = true; this.Label4.Location = new System.Drawing.Point(6, 133); this.Label4.Name = "Label4"; this.Label4.Size = new System.Drawing.Size(39, 13); this.Label4.TabIndex = 10; this.Label4.Text = "Label4"; // // Button2 // this.Button2.Location = new System.Drawing.Point(184, 45); this.Button2.Name = "Button2"; this.Button2.Size = new System.Drawing.Size(100, 23); this.Button2.TabIndex = 7; this.Button2.Text = "Save to XLS"; this.Button2.UseVisualStyleBackColor = true; this.Button2.Click += new System.EventHandler(this.Button2_Click); // // Button4 // this.Button4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.Button4.Location = new System.Drawing.Point(9, 175); this.Button4.Name = "Button4"; this.Button4.Size = new System.Drawing.Size(135, 23); this.Button4.TabIndex = 14; this.Button4.Text = "Recalculate"; this.Button4.UseVisualStyleBackColor = true; this.Button4.Click += new System.EventHandler(this.Button4_Click); // // Button1 // this.Button1.Location = new System.Drawing.Point(184, 16); this.Button1.Name = "Button1"; this.Button1.Size = new System.Drawing.Size(100, 23); this.Button1.TabIndex = 6; this.Button1.Text = "Load from XLS"; this.Button1.UseVisualStyleBackColor = true; this.Button1.Click += new System.EventHandler(this.Button1_Click); // // Button3 // this.Button3.Location = new System.Drawing.Point(184, 74); this.Button3.Name = "Button3"; this.Button3.Size = new System.Drawing.Size(100, 23); this.Button3.TabIndex = 8; this.Button3.Text = "View in Excel"; this.Button3.UseVisualStyleBackColor = true; this.Button3.Click += new System.EventHandler(this.Button3_Click); // // TextBox4 // this.TextBox4.Location = new System.Drawing.Point(9, 149); this.TextBox4.Name = "TextBox4"; this.TextBox4.Size = new System.Drawing.Size(135, 20); this.TextBox4.TabIndex = 13; // // Label5 // this.Label5.Location = new System.Drawing.Point(9, 240); this.Label5.Name = "Label5"; this.Label5.Size = new System.Drawing.Size(275, 113); this.Label5.TabIndex = 9; this.Label5.Text = resources.GetString("Label5.Text"); // // TextBox2 // this.TextBox2.Location = new System.Drawing.Point(9, 71); this.TextBox2.Name = "TextBox2"; this.TextBox2.Size = new System.Drawing.Size(135, 20); this.TextBox2.TabIndex = 9; // // Label2 // this.Label2.AutoSize = true; this.Label2.Location = new System.Drawing.Point(6, 55); this.Label2.Name = "Label2"; this.Label2.Size = new System.Drawing.Size(39, 13); this.Label2.TabIndex = 8; this.Label2.Text = "Label2"; // // GroupBox1 // this.GroupBox1.Controls.Add(this.Button4); this.GroupBox1.Controls.Add(this.TextBox4); this.GroupBox1.Controls.Add(this.Label3); this.GroupBox1.Controls.Add(this.TextBox3); this.GroupBox1.Controls.Add(this.Label4); this.GroupBox1.Controls.Add(this.TextBox2); this.GroupBox1.Controls.Add(this.Label2); this.GroupBox1.Controls.Add(this.TextBox1); this.GroupBox1.Controls.Add(this.Label1); this.GroupBox1.Location = new System.Drawing.Point(12, 10); this.GroupBox1.Name = "GroupBox1"; this.GroupBox1.Size = new System.Drawing.Size(166, 212); this.GroupBox1.TabIndex = 5; this.GroupBox1.TabStop = false; // // TextBox1 // this.TextBox1.Location = new System.Drawing.Point(9, 32); this.TextBox1.Name = "TextBox1"; this.TextBox1.Size = new System.Drawing.Size(135, 20); this.TextBox1.TabIndex = 7; // // Label1 // this.Label1.AutoSize = true; this.Label1.Location = new System.Drawing.Point(6, 16); this.Label1.Name = "Label1"; this.Label1.Size = new System.Drawing.Size(39, 13); this.Label1.TabIndex = 6; this.Label1.Text = "Label1"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 362); this.Controls.Add(this.Button2); this.Controls.Add(this.Button1); this.Controls.Add(this.Button3); this.Controls.Add(this.Label5); this.Controls.Add(this.GroupBox1); this.Name = "Form1"; this.Text = "Form1"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.Load += new System.EventHandler(this.Form1_Load); this.GroupBox1.ResumeLayout(false); this.GroupBox1.PerformLayout(); this.ResumeLayout(false); } #endregion internal System.Windows.Forms.Label Label3; internal System.Windows.Forms.TextBox TextBox3; internal System.Windows.Forms.Label Label4; internal System.Windows.Forms.Button Button2; internal System.Windows.Forms.Button Button4; internal System.Windows.Forms.Button Button1; internal System.Windows.Forms.Button Button3; internal System.Windows.Forms.TextBox TextBox4; internal System.Windows.Forms.Label Label5; internal System.Windows.Forms.TextBox TextBox2; internal System.Windows.Forms.Label Label2; internal System.Windows.Forms.GroupBox GroupBox1; internal System.Windows.Forms.TextBox TextBox1; internal System.Windows.Forms.Label Label1; } }

ON-PREMISE OFFLINE SDK

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

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Form1.cs
      
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Text; using System.Windows.Forms; using Bytescout.Spreadsheet; namespace SimpleDatabase { public partial class Form1 : Form { Spreadsheet _spreadsheet; private void LoadXLS() { Worksheet worksheet; _spreadsheet = new Spreadsheet(); _spreadsheet.LoadFromFile("Database.xls"); worksheet = _spreadsheet.Workbook.Worksheets[0]; Label1.Text = (string)worksheet.Cell("A1").Value; TextBox1.Text = worksheet.Cell("A2").Value.ToString(); Label2.Text = (string)worksheet.Cell("B1").Value; TextBox2.Text = worksheet.Cell("B2").Value.ToString(); Label3.Text = (string)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.ToString(); } private void SaveXLS() { Worksheet 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 (Exception ex) { } _spreadsheet.SaveAs("Database.xls"); } public Form1() { InitializeComponent(); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { SaveXLS(); _spreadsheet.Close(); } private void ReCalculate() { Worksheet 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.ToString(); } private void Button4_Click(object sender, EventArgs e) { ReCalculate(); } private void Form1_Load(object sender, EventArgs e) { LoadXLS(); } private void Button3_Click(object sender, EventArgs e) { // open in default spreadsheets viewer/editor SaveXLS(); try { Process.Start("Database.xls"); } catch { } } private void Button1_Click(object sender, EventArgs e) { LoadXLS(); MessageBox.Show("Loaded from Database.xls"); } private void Button2_Click(object sender, EventArgs e) { SaveXLS(); MessageBox.Show("Saved into Database.xls"); } } }

ON-PREMISE OFFLINE SDK

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

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Program.cs
      
using System; using System.Collections.Generic; using System.Windows.Forms; namespace SimpleDatabase { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }

ON-PREMISE OFFLINE SDK

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

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

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

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next