XDoc.Excel
Features
Tech Specs
How-to C#
Pricing

C# Excel Library
How to C#: Load, Save Excel Document


Overview for How to Use XDoc.Excel to load and save Excel document in C# .NET Programming Project





RasterEdge XDoc.Excel has provided three ways to create Excel document object that are load from file, load from stream and load from byte array.Conversely, the Excel SDK can also save Excel document object to file, stream or byte array.


Load Excel Document From Existing File Using C#



You may also load or create a Excel document object from existing Excel file in C#.net.

//  Load from a file
String inputFilePath  = Program.RootPath + "\\" + "1.xlsx";
XLSXDocument doc = new XLSXDocument(inputFilePath);
if (doc == null) throw new Exception("fail to load the file");
//  ...


Load Excel From Stream Object in C# Project



Excel document can be loaded from a stream object in C# programming.

//  Load from a stream
String inputFilePath = Program.RootPath + "\\" + "2.xlsx";
using (FileStream fileStream = File.Open(inputFilePath, FileMode.Open, FileAccess.Read))
{
    XLSXDocument doc = new XLSXDocument(fileStream);
    if (doc == null) throw new Exception("fail to load Excel document from the stream");
    //  ...
}


Load Excel From Byte Array Object in C# Project



Excel document can be loaded from a stream object in C# programming.

//  Load from a stream
String inputFilePath = Program.RootPath + "\\" + "2.xlsx";
using (FileStream fileStream = File.Open(inputFilePath, FileMode.Open, FileAccess.Read))
{
    byte[] array = new byte[fileStream.Length];
    fileStream.Read(array, 0, array.Length);
    XLSXDocument doc = new XLSXDocument(fileStream);
    if (doc == null) throw new Exception("fail to load Excel document from the stream");
    //  ...
}


Save Excel Document To File in C# Project



Excel document can be saved to a Excel file in C# programming.

String inputFilePath = Program.RootPath + "\\" + "2.xlsx";
String outputFilePath = Program.RootPath + "\\" + "output.xlsx";
XLSXDocument doc = new XLSXDocument(fileStream);
if (doc == null) throw new Exception("fail to load Excel document from the stream");
//  Save document to a Excel file
doc.Save(outputFilePath);


Save Excel Document To Stream Object in C# Project



Excel document can be saved to a stream object in C# programming.

String inputFilePath = Program.RootPath + "\\" + "2.xlsx";
Stream stream = new MemoryStream();
XLSXDocument doc = new XLSXDocument(fileStream);
if (doc == null) throw new Exception("fail to load Excel document from the stream");
//  Save document  to  a stream object
doc.SaveToStream(stream);


Save Excel Document To Byte Array in C# Project



Excel document can be saved to a byte array object in C# programming.

String inputFilePath = Program.RootPath + "\\" + "2.xlsx";
XLSXDocument doc = new XLSXDocument(inputFilePath);
if (doc == null) throw new Exception("fail to load Excel document from the stream");
//  Save document to a byte array object
byte[] array = doc.SaveToByte();