Bsa.Pdf.Office
1.0.42
dotnet add package Bsa.Pdf.Office --version 1.0.42
NuGet\Install-Package Bsa.Pdf.Office -Version 1.0.42
<PackageReference Include="Bsa.Pdf.Office" Version="1.0.42" />
<PackageVersion Include="Bsa.Pdf.Office" Version="1.0.42" />
<PackageReference Include="Bsa.Pdf.Office" />
paket add Bsa.Pdf.Office --version 1.0.42
#r "nuget: Bsa.Pdf.Office, 1.0.42"
#:package Bsa.Pdf.Office@1.0.42
#addin nuget:?package=Bsa.Pdf.Office&version=1.0.42
#tool nuget:?package=Bsa.Pdf.Office&version=1.0.42
Bsa.Pdf.Office
Writing Word documents (.docx), Excel workbooks (.xlsx) and PowerPoint presentations (.pptx) in pure C#: no Open XML SDK, NPOI, EPPlus or any other library. .NET 6, .NET 8, .NET 10 — Windows, Linux, macOS. The files open in Microsoft Office, LibreOffice, R7-Office and MyOffice.
Documentation in Russian: README.ru.md in the package.
Installation
dotnet add package Bsa.Pdf.Office
All sizes are in points (1/72 inch), colors are RRGGBB strings.
Word
using System.IO;
using Bsa.Pdf.Office.Word;
var document = new DocxDocument { Title = "Report", FontName = "Times New Roman", FontSize = 12, Language = "en-US" };
document.AddParagraph(new DocxParagraph
{
Alignment = DocxAlignment.Center,
HeadingLevel = 1,
Runs = { new DocxRun { Text = "Quarterly report", Bold = true, FontSize = 16 } },
});
document.AddParagraph(DocxParagraph.Of("A regular paragraph.\nThe second line of the same paragraph."));
document.AddTable(new[]
{
new[] { "Indicator", "Value" },
new[] { "Revenue", "1,250,000" },
});
document.AddPageBreak();
document.AddParagraph(new DocxParagraph
{
IndentLeft = 36,
Runs = { new DocxRun { Text = "Indented", Italic = true, Color = "C00000", Link = "https://example.com" } },
});
// Page number in the footer.
document.Footer.Add(new DocxParagraph
{
Alignment = DocxAlignment.Right,
Runs = { new DocxRun { Text = "Page " }, new DocxRun { Field = DocxField.Page } },
});
File.WriteAllBytes("report.docx", document.Save());
| Type | What it sets |
|---|---|
DocxDocument |
Page (sheet size and margins, A4 with 2 cm margins by default), FontName, FontSize, Language, Title, Header, Footer; AddParagraph, AddTable, AddImage (PNG or JPEG as a separate paragraph; wider than the text area — scaled down), AddFootnote, AddPageBreak, AddSectionBreak, EmbedFont, Save |
DocxParagraph |
Runs, Alignment (Left, Center, Right, Justify), IndentLeft, FirstLineIndent, SpaceBefore, SpaceAfter, LineSpacing, Tabs, List, HeadingLevel, PageBreakBefore, floating Pictures and Shapes |
DocxRun |
Text (a line feed is a line break), Bold, Italic, Underline, Strike, FontSize, FontName, Color, Highlight, Link, Field (Page, NumPages, PageRef), FootnoteId |
DocxTableModel |
Tables with column widths, merged cells, borders, shading and nested tables (AddTable(DocxTableModel)) |
Footnotes: AddFootnote(paragraphs) returns the footnote number; put a run with FootnoteId set to that number
where the footnote mark should be.
Excel
using System.IO;
using Bsa.Pdf.Office.Excel;
var book = new XlsxWorkbook { Title = "Registry" };
var sheet = book.AddSheet("Payments");
var header = new XlsxCellStyle { Bold = true, Fill = "D9E1F2", Horizontal = XlsxHorizontalAlignment.Center };
sheet.SetText(0, 0, "Date");
sheet.SetText(0, 1, "Amount");
sheet.SetStyle(0, 0, header);
sheet.SetStyle(0, 1, header);
sheet.SetText(1, 0, "2026-11-18");
sheet.SetNumber(1, 1, 1250.5);
sheet.SetStyle(1, 1, new XlsxCellStyle { NumberFormat = "#,##0.00" });
sheet.SetColumnWidth(0, 14);
File.WriteAllBytes("registry.xlsx", book.Save());
Rows and columns are zero-based (XlsxSheet.CellName(0, 0) is A1). XlsxSheet also has Merge, SetRowHeight
and SetColumnWidth; XlsxCellStyle sets the font, color, fill, borders (XlsxBorder), alignment, wrapping and
number format. A sheet name is cleaned of invalid characters and shortened to 31 characters; a repeated name gets
a number.
PowerPoint
A slide is a sheet of a given size with shapes (lines, rectangles, text boxes, tables) and pictures at their places (points, origin at the top left):
using System.IO;
using Bsa.Pdf.Office.PowerPoint;
using Bsa.Pdf.Office.Word;
var presentation = new PptxPresentation { Title = "Results", Language = "en-US" };
presentation.Slides.Add(new PptxSlide
{
Width = 960,
Height = 540,
Shapes =
{
new DocxShape
{
Kind = DocxShapeKind.TextBox,
Left = 60, Top = 40, Width = 840, Height = 80,
Paragraphs = { new DocxParagraph { Runs = { new DocxRun { Text = "Results", Bold = true, FontSize = 36 } } } },
},
},
Pictures =
{
new DocxFloatingPicture { Data = File.ReadAllBytes("chart.png"), Format = DocxImageFormat.Png, Left = 60, Top = 140, Width = 480, Height = 320 },
},
});
File.WriteAllBytes("results.pptx", presentation.Save());
Reading
Reading is meant for layout (converting to PDF):
- Word —
Bsa.Pdf.Office.Word.Reading.DocxReader: sections, headers and footers, paragraphs with formatting from styles and the theme, lists, tables, images. - Excel —
Bsa.Pdf.Office.Excel.Reading.XlsxReader: visible sheets, displayed cell text by number and date formats (XlsxNumberFormat), cell styles, row and column sizes, merges, print settings and print area; no formula calculation.
Limitations
- Word: images in a paragraph are inline or floating; no comments, tracked changes or content controls.
- Excel: values are written, formulas are not; no charts or images.
- PowerPoint: no slide masters, animations or transitions.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bsa.Pdf.Office:
| Package | Downloads |
|---|---|
|
Bsa.Pdf.Convert
Convert Word (.docx), Excel (.xlsx) and PDF documents to page images (PNG, JPEG, multi-page TIFF) and Word/Excel to PDF in C#: own layout engine for paragraphs, tables, headers and footers, footnotes, EMF/WMF pictures and Excel charts; pages are rendered with PDFium. No Microsoft Office, LibreOffice or Open XML SDK; Windows, Linux, macOS. |
GitHub repositories
This package is not used by any popular GitHub repositories.