如何使用EPPlus在单个Excel单元中加载包含逗号的文本 [英] How to load text containing commas in a single Excel cell with EPPlus

查看:107
本文介绍了如何使用EPPlus在单个Excel单元中加载包含逗号的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 EPPlus库,但我坚持这样做:我必须在单个单元格中加载文本,但是当此文本包含逗号时,我正在使用的代码将文本沿多个单元格分割(沿正确的方向)。
这是我用来加载文本的代码:

I'm giving a try to the EPPlus library and I'm stucked at this: I have to load a text in a single cell, but when this text contains a comma the code that I'm using split my text along multiple cells (along the right direction). Here is the code that I'm using to load the text:

using (ExcelPackage pck = new ExcelPackage())
{
   //Create the worksheet
   ExcelWorksheet ws = pck.Workbook.Worksheets.Add("MySheet");
   using (ExcelRange range = ws.Cells[1, 1])
   {
      range.LoadFromText("this works");
   }
   using (ExcelRange range = ws.Cells[1, 2])
   {
      range.LoadFromText("this, splits my , text in 3 parts");
   }
}

我找不到在a上进行操作的方法或指示LoadFromText方法不要拆分文本。

I don't find a way to operate on a single cell or to instruct the LoadFromText method to not split my text.

推荐答案

您可以通过指定 TextQualifier

using (ExcelRange range = ws.Cells[1, 1])
{
   var format = new OfficeOpenXml.ExcelTextFormat();
   format.Delimiter = ',';
   format.TextQualifier = '"';
   format.DataTypes = new[] { eDataTypes.String };
   range.LoadFromText("this, should, work, also, now", format);
}

这篇关于如何使用EPPlus在单个Excel单元中加载包含逗号的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆