Skip to content

Latest commit

History

98 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Fast Excel

Build / Release

Build statusLicenseNuGet Badge

About

  • Provides a fast way of reading and writing to *.xlsx Excel files.
  • Small memory footprint while running
  • Does not use the Open XML SDK to interact with the data but going directly and editing the underlying xml files.
  • This project is not intended to be a replacement for full featured Excel packages with things like formatting, just light weight fast way of interacting with data in Excel.

Version 2

  • Contribute using Visual Studio 2017
  • Built using .NetStandard 1.3 so it should run on
    • .Net Core 1.0
    • .Net Framework 4.6
    • Mono
    • Xamarin.iOS
    • Xamarin.Androud
    • Universal Windows Platform

Version 1 (old)

Build status

  • Built using .Net Framework 4.5
  • Contribute using Visual Studio 2015
  • This version may not be up to date

Installation

PM> Install-Package FastExcel

Write Demo 1

This demo uses Generic objects, ie any object you wish with public properties

using(FastExcel.FastExcelfastExcel=newFastExcel.FastExcel(outputFile)){List<MyObject>objectList=newList<MyObject>();for(introwNumber=1;rowNumber<NumberOfRecords;rowNumber++){MyObjectgenericObject=newMyObject();genericObject.StringColumn1="A string "+rowNumber.ToString();genericObject.IntegerColumn2=45678854;genericObject.DoubleColumn3=87.01d;genericObject.ObjectColumn4=DateTime.Now.ToLongTimeString();objectList.Add(genericObject);}fastExcel.Write(objectList,"sheet3",true);}

Write Demo 2

This demo lets you specify exactly which cell you are writing to

// Get your template and output file pathsFileInfotemplateFile=newFileInfo("Template.xlsx");FileInfooutputFile=newFileInfo("C:\\Temp\\output.xlsx");//Create a worksheet with some rowsWorksheetworksheet=newWorksheet();List<Row>rows=newList<Row>();for(introwNumber=1;rowNumber<100000;rowNumber++){List<Cell>cells=newList<Cell>();for(intcolumnNumber=1;columnNumber<13;columnNumber++){cells.Add(newCell(columnNumber,columnNumber*DateTime.Now.Millisecond));}cells.Add(newCell(13,"Hello"+rowNumber));cells.Add(newCell(14,"Some Text"));rows.Add(newRow(rowNumber,cells));}worksheet.Rows=rows;// Create an instance of FastExcelusing(FastExcel.FastExcelfastExcel=newFastExcel.FastExcel(templateFile,outputFile)){// Write the datafastExcel.Write(worksheet,"sheet1");}

Read Demo 1 Get Worksheet

// Get the input file pathsFileInfoinputFile=newFileInfo("C:\\Temp\\input.xlsx");//Create a worksheetDataSetworksheet=null;// Create an instance of Fast Excelusing(FastExcel.FastExcelfastExcel=newFastExcel.FastExcel(inputFile,true)){// Read the rows using worksheet nameworksheet=fastExcel.Read("sheet1");// Read the rows using the worksheet index// Worksheet indexes are start at 1 not 0// This method is slightly faster to find the underlying file (so slight you probably wouldn't notice)worksheet=fastExcel.Read(1);}

Read Demo 2 Get All Worksheets

// Get the input file pathsFileInfoinputFile=newFileInfo("C:\\Temp\\fileToRead.xlsx");// Create an instance of Fast Excelusing(FastExcel.FastExcelfastExcel=newFastExcel.FastExcel(inputFile,true)){foreach(varworksheetinfastExcel.Worksheets){Console.WriteLine(string.Format("Worksheet Name:{0}, Index:{1}",worksheet.Name,worksheet.Index));//To read the rows call readworksheet.Read();varrows=worksheet.Rows.ToArray();//Do something with rowsConsole.WriteLine(string.Format("Worksheet Rows:{0}",rows.Count()));}}

Update Demo

// Get the input file pathsFileInfoinputFile=newFileInfo("C:\\Temp\\input.xlsx");//Create a some rows in a worksheetWorksheetworksheet=newWorksheet();List<Row>rows=newList<Row>();for(introwNumber=1;rowNumber<NumberOfRecords;rowNumber+=50){List<Cell>cells=newList<Cell>();for(intcolumnNumber=1;columnNumber<13;columnNumber+=2){cells.Add(newCell(columnNumber,rowNumber));}cells.Add(newCell(13,"Updated Row"));rows.Add(newRow(rowNumber,cells));}worksheet.Rows=rows;// Create an instance of Fast Excelusing(FastExcel.FastExcelfastExcel=newFastExcel.FastExcel(inputFile)){// Read the datafastExcel.Update(worksheet,"sheet1");}

Thanks to

  • Sibz

  • paritoshmmmec

  • Insperation for this project came from SejExcelExport by jsegarra1971 who did a great job. I wanted to have my own crack at this problem.

About

Fast Excel Reading C# and Fast Excel Writing C#

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages