also available as:
The tech support is by far the best I have ever worked within 27 years of development. Questions are answered quickly and program fixes are created and are made available.
– Dennis
|
Read and write Excel XLS, XLSX, CSV files |
Bytescout Spreadsheet SDK is a clean and simple API to read and write Excel files.
Almost in every business application we need to have the ability to read and write Excel files. Using Bytescout Spreadsheet SDK is a simple way of reading and writing Excel files using C# (CSharp).
Sample source code – write data to Excel file in C#:
using System;
using System.Collections.Generic;
using System.Text;
using Bytescout.Spreadsheet;
using System.IO;
using System.Diagnostics;
<span data-scayt_word="namespace" data-scaytid="5">namespace</span> <span data-scayt_word="HelloWorld" data-scaytid="6">HelloWorld</span>
{
class Program
{
static void Main(string[] <span data-scayt_word="args" data-scaytid="8">args</span>)
{
// Create new Spreadsheet
Spreadsheet document = new Spreadsheet();
// Add new worksheet
Worksheet worksheet = document.Workbook.Worksheets.Add("<span data-scayt_word="HelloWorld" data-scaytid="7">HelloWorld</span>");
// Set cell value
worksheet.Cell(0, 0).Value = "Hello, World!";
// delete output file if exists already
if (File.Exists("Output.xls")){
File.Delete("Output.xls");
}
// Save document
document.SaveAs("Output.xls");
// Close Spreadsheet
document.Close();
// open generated <span data-scayt_word="XLS" data-scaytid="4">XLS</span> document in default program
Process.Start("Output.xls");
}
}
}
Sample source code – read data from Excel file in C#:
using System;
using System.Collections.Generic;
using System.Text;
using Bytescout.Spreadsheet;
<span data-scayt_word="namespace" data-scaytid="10">namespace</span> <span data-scayt_word="HelloWorld" data-scaytid="11">HelloWorld</span>
{
class Program
{
static void Main(string[] <span data-scayt_word="args" data-scaytid="12">args</span>)
{
// Create new Spreadsheet
Spreadsheet document = new Spreadsheet();
document.LoadFromFile("Hello_world.xlsx");
// Get worksheet
Worksheet worksheet = document.Workbook.Worksheets.ByName("<span data-scayt_word="Sheet1" data-scaytid="16">Sheet1</span>");
// Read cell value
Console.WriteLine("Cell (0,0) value: {0}", worksheet.Cell(0, 0).ValueAsString);
// Write message
Console.Write("Press any key to continue...");
// Wait user input
Console.ReadKey();
}
}
}
Find all sample source codes for C Sharp and ASP.NET in a free trial of Spreadsheet SDK. Download now!
[socialpug_share]