EPPlus - 导出带有前导单引号的字符串值
EPPlus - Exporting string values with leading single quotation mark
我正在尝试使用 C# 和 EPPlus 库将数据写入 xlsx 文件。到目前为止工作正常,但是:我写的所有值都必须以单引号 (') 开头。如果我把那个写到一个单元格中(例如“'MyName"), and afterwards open the Excel file in Excel, the ' 显示在所有单元格中!通常,当你在 Excel 中写这个前导引号时,它不会显示在单元格中,只显示在公式。
在我的例子中,如果我转到一个单元格,编辑公式并点击 "Return",正常行为又回来了。但不是在导出之后,当然在所有单元格上点击 return 不是一个选项。
有什么想法吗?我用谷歌搜索了很多都没有成功...
WorkSheet.Cells[1, 4].Value = "'nameFirstname";
WorkSheet.Cells[1, 5].Value = "'1";
根据您的评论,我现在明白了。要包含 Excell 识别的单引号,请像这样设置选项:
ws.Cells[1, 4].Value= "namefirstname"; //No single quote needed
ws.Cells[1, 4].Style.QuotePrefix = true;
我正在尝试使用 C# 和 EPPlus 库将数据写入 xlsx 文件。到目前为止工作正常,但是:我写的所有值都必须以单引号 (') 开头。如果我把那个写到一个单元格中(例如“'MyName"), and afterwards open the Excel file in Excel, the ' 显示在所有单元格中!通常,当你在 Excel 中写这个前导引号时,它不会显示在单元格中,只显示在公式。 在我的例子中,如果我转到一个单元格,编辑公式并点击 "Return",正常行为又回来了。但不是在导出之后,当然在所有单元格上点击 return 不是一个选项。
有什么想法吗?我用谷歌搜索了很多都没有成功...
WorkSheet.Cells[1, 4].Value = "'nameFirstname";
WorkSheet.Cells[1, 5].Value = "'1";
根据您的评论,我现在明白了。要包含 Excell 识别的单引号,请像这样设置选项:
ws.Cells[1, 4].Value= "namefirstname"; //No single quote needed
ws.Cells[1, 4].Style.QuotePrefix = true;