Apply Formatting to Numbers, Dates, and Text in C#
Leave feedback
Overview
GroupDocs.Assembly for .NET provides comprehensive formatting capabilities for numbers, dates, and text in templates. You can use format strings (similar to .NET formatting) and built-in text transformation functions to control how data is displayed in your documents.
The main syntax elements are:
Format strings: <<[expression]:"format">> - apply .NET format strings
Text functions: upper, lower, capital, firstcap - transform text case
Here are the steps to apply formatting:
Use format strings in expression tags for numbers and dates
Apply text transformation functions for string formatting
Combine formatting with expressions and calculations
Test formatting to ensure desired output
Note
Format strings follow .NET formatting conventions. Use standard numeric format specifiers (C, N, F, etc.) and date/time format strings (yyyy-MM-dd, etc.).
Formatting works consistently across document types:
usingGroupDocs.Assembly;publicstaticvoidFormatInSpreadsheet(){varinvoice=newInvoice{Amount=1500.75m,CreatedDate=DateTime.Now};DocumentAssemblerassembler=newDocumentAssembler();assembler.AssembleDocument("FormattingTemplate.xlsx","FormattingOutput.xlsx",newDataSourceInfo(invoice,"invoice"));Console.WriteLine("Formatting applied in spreadsheet successfully.");}
Warning
Format strings are case-sensitive. Use uppercase letters for standard format specifiers (C, N, F, P) and follow .NET formatting conventions exactly.
Advanced Usage Topics
To learn more about custom format providers, culture-specific formatting, and advanced formatting scenarios, please refer to the advanced usage section.
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: