Mats Alm edited this page Nov 7, 2023 · 13 revisions
This method exports a range in a worksheet to a string. You can configure the format of this content by using the ExcelOutputTextFormat class as input parameter. This method generates the same output as the SaveToText method, which sends the output to a file instead of a string.
Lets create a worksheet and add some values to the cells:
using(var package = new ExcelPackage(u))
{
var sheet = package.Workbook.Worksheets.Add("test");
sheet.Cells["A1"].Value = 1;
sheet.Cells["B1"].Value = 2;
sheet.Cells["A2"].Value = 3;
sheet.Cells["B2"].Value = 4;
}
...and then call the ToText
method:
var content = sheet.Cells["A1:B2"].ToText();
The value of the string content will be "1,2\r\n3,4";
An instance of this class can be sent in as a parameter to the ToText
method.
var format = new ExcelOutputTextFormat{
TextQualifier = '\''
};
var content = sheet.Cells["A1:B2"].ToText(format);
The ExcelOutputTextFormat
class has the following properties:
Property | Datatype | Default value | Description |
---|---|---|---|
Delimiter |
char |
',' (comma) |
Delimiter character |
TextQualifier |
char |
'\0' (null) |
A character that encapsulates text |
EOL |
string |
"\r\n" |
End of line characters |
Culture |
CultureInfo |
CultureInfo.InvariantCulture |
Culture used when parsing cell values |
SkipLinesBeginning |
int |
0 | Number of lines skipped at the end |
SkipLinesEnd |
int |
0 | Number of lines skipped at the end |
Encoding |
Encoding |
Encoding.ASCII |
Only used when reading/writing files from disk using a FileInfo object |
Header |
string |
null |
A text written at the start of the content |
Footer |
string |
null |
A text written at the start of the content |
FirstRowIsHeader |
bool |
true |
First row of the range contains the headers. All header cells will be treated as strings |
UseCellFormat |
bool |
true |
Use the cells Text property with the applied culture. This only applies to columns with no format set in the Formats collection. If SkipLinesBeginning (see above) is larger than zero, headers will still be read from the first row in the range. If a TextQualifier (see above) is set, non numeric and date columns will be wrapped with the TextQualifier. |
Formats |
string[] |
null |
A specific .NET format for the column. Format is applied with the used culture. For a text column use $ as format. |
DecimalSeparator |
string |
null |
Decimal separator, if other than the used culture. |
ThousandsSeparator |
string |
null |
Thousands separator, if other than the used culture |
EncodedTextQualifier |
string |
null |
What to replace the TextQualifier with inside a text when TextQualifier is set. Default is two TextQualifier characters, for example " is replaced with "" |
EPPlus Software AB - https://epplussoftware.com
Pages 107
EPPlus wiki
- Getting Started
- The Sample Project
- EPPlus and Docker
- EPPlus and Blazor
- EPPlus and Linux
- Security
- Configuration
- Releases/versioning
Versions
- What is new in EPPlus 5+
- Breaking Changes in EPPlus 5
- Breaking Changes in EPPlus 6
- Breaking Changes in EPPlus 7
Worksheet & Ranges
- Addressing a worksheet
- Dimension/Used range
- Copying ranges/sheets
- Insert/Delete
- Filling ranges
- Sorting ranges
- Taking and skipping columns/rows
- Data validation
- Comments
- Freeze and Split Panes
- Header and Footer
- Autofit columns
- Grouping and Ungrouping Rows and Columns
Styling
- Formatting and styling
- Conditional formatting
- Using Themes
- Working with custom named table- or slicer- styles
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现