Find out how to make your life easier with SpreadsheetLight (often with a handful of lines of code). Obviously I can’t show you everything that SpreadsheetLight is capable of. If you can’t find any sample code here to do what you want, and you’re on a tight schedule, just contact me and I’ll show you how to accomplish your specific requirement.
You can read and modify existing Excel spreadsheets, even though SpreadsheetLight is optimised for creating brand new spreadsheets. In any case, your server will probably register nary a blip in performance and memory use. Micro-optimisation, down that path thou shalt not go.
Download it now, or check out the speed/memory benchmark code if you’re not ready yet.
Possibly the shallowest learning curve ever. Because you’re worth it.
- The Hello World. This takes you through the basics of setting cell values. [Excel file]
- How to save to a web stream (useful for ASP.NET applications). [Excel file]
- How to modify an existing spreadsheet. [Original Excel file] [Modified Excel file]
- How to set document properties (or metadata). [Excel file]
- How to work with multiple spreadsheets at the same time (or at one go anyway). [First file] [Second file] [Modified second file] [Resulting file]
- How to open a spreadsheet that’s in a Stream object. [Original Excel file] [Modified Excel file]
- How to set cell comments. [Excel file]
- How to do LINQ stuff with cell data, get worksheet statistics and more. [Excel file]
- How to export to a DataTable. [Source Excel file] [1st DataTable XML] [2nd DataTable XML]
Tip: You might find the SLConvert class to be helpful in doing miscellaneous conversions, such as getting cell references from a row/column index, as well as converting centimetres to inches (Excel by default follows the imperial system instead of using the metric system. Unlike most civilised countries *cough*
Tip: You can find out basic worksheet statistics with SLWorksheetStatistics. For example, the number of rows/columns/cells used. Use the GetWorksheetStatistics() of the SLDocument class.
You’ve got style
- How to format numbers and dates. [Excel file]
- How to handle historic dates. For our purposes, any date before the year 1900 is considered “historic”. [Excel file]
- How to set text alignment. [Excel file]
- How to set font settings. [Excel file]
- How to set borders. [Excel file]
- How to set pattern fills and gradients (even fancy ones!). [Excel file]
- How to style your rows, columns and cells. And even copy styles around! [Excel file]
- How to use rich text. [Excel file]
- How to modify existing styles (of rows, columns and cells). [Excel file]
- How to use named cell styles (such as Good, Bad, Neutral, Check Cell, Heading 1 and more). [Excel file]
- How to set multiple lines of text in one cell (or how to wrap text). [Excel file]
- How to create new themes to style your spreadsheet! Or use one of 53 built-in themes! [Built-in themed Excel file] [Newly themed Excel file]
- How to copy cells (cut-and-paste, copy-and-paste, copy only values, copy only style formatting, copy from another worksheet). [Excel file]
- How to merge and unmerge cells. [Excel file]
- How to insert and delete rows and columns. [Excel file]
- How to copy entire rows and columns. [Excel file]
- How to hide rows and columns. [Excel file]
- How to set row heights and column widths. [Excel file]
- How to autofit row heights and column widths. NOTE: The provided Excel file is generated with a screen monitor at 120 DPI. If you read it at 96 DPI, the result might look different. [Excel file]
- How to group and ungroup rows and columns (and how to collapse and expand grouped rows and columns). [Excel file]
- How to add, copy, rename, move and delete worksheets. [Excel file]
- How to freeze and split worksheet panes. [Excel file]
- How to insert hyperlinks. [Excel file]
- How to insert pictures (with tons of fancy styling. We have 3D settings!). [Excel file]
- How to insert pictures with the image data in a byte array. [Excel file]
- How to add/delete background images. [Original Excel file] [Modified Excel file]
- How to set defined names. Defined names are what used to be called named cells and named ranges. [Excel file]
- How to insert tables. [Excel file]
- How to add data validations. [Excel file]
- How to filter data. [Excel file]
- How to sort data. [Excel file]
- How to insert and remove page breaks. [Excel file]
- How to set worksheet protection (no password). [Excel file]
- How to import data from a DataTable (for when you have a &%#*-ton of data to load). [Excel file]
- How to set the tab color of a sheet. [Excel file]
- How to set page margins. [Excel file]
- How to set simple page header and footer text. [Excel file]
- How to set page header and footer text in a more complicated manner (but highly flexible). [Excel file]
- How to set odd- and even-numbered page header and footer. [Excel file]
- How to set first page header and footer. [Excel file]
- How to set page settings such as orientation, paper size, draft quality and so on. [Excel file]
- How to set page layout (such as Normal, Page Layout and Page Break Preview). [Excel file]
- How to get the existing page settings of a worksheet (and then set it on another worksheet). [Existing Excel file] [Modified Excel file]
- How to set data bar conditional formats. [Excel file]
- How to set color scale conditional formats. [Excel file]
- How to set icon set conditional formats. [Excel file]
- How to set conditional formatting highlights. [Excel file]
- How to set Excel 2010 specific data bar conditional formats. [Excel file]
- How to set Excel 2010 specific icon set conditional formats (Look mom, no icons!). [Excel file]
- How to insert an area chart. [Excel file]
- How to insert a bar chart. [Excel file]
- How to insert a bubble chart. [Excel file]
- How to insert a column chart. [Excel file]
- How to insert a doughnut chart. [Excel file]
- How to insert a line chart. [Excel file]
- How to insert a pie chart. [Excel file]
- How to insert a radar chart. [Excel file]
- How to insert a scatter chart. [Excel file]
- How to insert a surface chart. [Excel file]
- How to insert a chart in a chartsheet. [Excel file]
- How to set and style the chart title. [Excel file]
- How to set and style the chart legend. [Excel file]
- How to set and style the chart area. [Excel file]
- How to set and style the chart plot area. [Excel file]
- How to set and style the floor, side wall and back wall of 3D charts. [Excel file]
- How to set and style the axis title of chart (works for primary, secondary and depth axis). [Excel file]
- How to set and style individual data series of a column chart. The column chart is used, but the concept works similarly for other kinds of charts. [Excel file]
- How to set and style the individual data series of a line chart. The line chart is used, but the concept works similarly for other kinds of charts. [Excel file]
- How to create a column-line-area combination chart. The concept works similarly for other types of combination charts. [Excel file]
- How to insert a data table in a chart. [Excel file]
- How to set data labels in a chart. [Excel file]
- How to set data point options in a chart. Yes, you can customise individual data points in a data series. [Excel file]
- How to create a thermometer chart. [Excel file]
- How to create a gauge chart. [Excel file]
- How to create a comparative histogram chart. [Excel file]
- How to create a Gantt chart. [Excel file]
- How to create sparklines. [Excel file]
- How to create column sparklines. [Excel file]
- How to create win/loss sparklines. [Excel file]
Work those worksheets
Page settings
Conditional formatting
How come there’s no Excel 2010 specific color scale conditional formats? Because Microsoft hasn’t seen fit to make my life miserable. Yet.
Charting
Novelty charts
Disclaimer: I’m not an Excel expert. Go check with your local spreadsheet geek on the details.
Sparklines
Note: You’ll probably need Excel 2010 and later to view the sparklines.
