C#: Online Guide
How To: excel SDK
Load, Save Document
  |  
Home ›› XDoc.Excel ›› C# Excel: Load, Save Document

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.


Related .net document control helps:
asp.net mvc file viewer: ASP.NET MVC Document Viewer: view, annotate, redact files on ASP.NET MVC web projects
asp.net create pdf control: ASP.NET Create PDF Document Control: create, convert PDF file from Word, Excel, Tiff file formats in C# ASP.NET
asp.net sharepoint file viewer: ASP.NET SharePoint Document Viewer: view, annotate, redact documents in SharePoint
asp.net azure pdf editor control: ASP.NET Azure PDF Editor Control: view, edit, annotate, redact PDF files online
asp.net pdf file viewer: ASP.NET PDF Document Viewer in C#: view, annotate, redact Adobe PDF files online in ASP.NET
asp.net dnn file viewer: DNN Document Viewer Control: view, annotate, redact, convert documents in dotnetnuke ASP.NET
asp.net edit pdf page control: ASP.NET PDF Pages Edit Control: add, remove, sort, replace PDF pages online using C#




C# DLLs: Load and Save Excel Document



Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.XDoc.Excel.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XImage.Raster.dll


Using namespaces:


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.Excel;




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();