EPPlus在超过65530行时损坏Excel文件
当有超过65530行包含带有超链接的列时,我遇到了EPPlus的问题。下面的示例配置为创建65530行。使用此数字将正确创建Excel文件,而不会损坏。一旦您使用超过65530的任何内容运行它,将创建Excel文件,但当您打开它时,Excel将报告该文件已损坏。有没有办法解决这个问题EPPlus在超过65530行时损坏Excel文件,excel,hyperlink,epplus,corrupt,Excel,Hyperlink,Epplus,Corrupt,当有超过65530行包含带有超链接的列时,我遇到了EPPlus的问题。下面的示例配置为创建65530行。使用此数字将正确创建Excel文件,而不会损坏。一旦您使用超过65530的任何内容运行它,将创建Excel文件,但当您打开它时,Excel将报告该文件已损坏。有没有办法解决这个问题 try { int maxRowsToCreate = 65530; //-- no errors will be generated //int maxRowsToCreate = 65531
try
{
int maxRowsToCreate = 65530; //-- no errors will be generated
//int maxRowsToCreate = 65531; //-- error will be generated. The Excel file will be created but will give an error when trying to open it.
string report = string.Format("D:\\temp\\hypelinkIssue-{0}.xlsx", maxRowsToCreate.ToString());
if (File.Exists(report))
{
File.Delete(report);
}
using (ExcelPackage pck = new ExcelPackage(new System.IO.FileInfo(report)))
{
//Add the Content sheet
var ws = pck.Workbook.Worksheets.Add("Catalog");
ws.View.ShowGridLines = true;
var namedStyle = pck.Workbook.Styles.CreateNamedStyle("HyperLink"); //This one is language dependent
namedStyle.Style.Font.UnderLine = true;
namedStyle.Style.Font.Color.SetColor(Color.Blue);
ws.Column(1).Width = 100;
int rowIndex = 0;
for (int i = 0; i < maxRowsToCreate; i++)
{
rowIndex += 1;
string fullFilePath = string.Format("D:\\temp\\{0}", Path.GetRandomFileName());
ws.Cells[rowIndex, 1].StyleName = "HyperLink";
ws.Cells[rowIndex, 1].Hyperlink = new Uri(string.Format(@"file:///{0}", fullFilePath));
ws.Cells[rowIndex, 1].Value = fullFilePath;
}
pck.Save();
}
System.Diagnostics.Process.Start(report);
}
catch (Exception ex)
{
throw ex;
}
这是因为Excel将文件中唯一URL的数量限制为65530。您应该尝试将它们作为文本而不是url插入
对于可能的解决方案,请查看。这是因为Excel将文件中唯一URL的数量限制为65530。您应该尝试将它们作为文本而不是url插入
有关可能的解决方案,请查看。使用.Hyperlink时会出现此问题。如果我改为使用.Formula并用=HYPERLINK Excel公式填充它,则效果很好。我能够使用这种方法创建具有唯一超链接的250k记录。我没有尝试超过25万,但希望它会工作的很好 谢谢你给我指明了正确的方向
/*
This only works with LESS than 65,530 hyperlinks
*/
ws.Cells[rowIndex, 1].StyleName = "HyperLink";
ws.Cells[rowIndex, 1].Hyperlink = new OfficeOpenXml.ExcelHyperLink(fullFilePath, ExcelHyperLink.UriSchemeFile);
ws.Cells[rowIndex, 1].Value = fullFilePath;
/*
This works with more that 65,530 hyperlinks
*/
string cellFormula = string.Format("=HYPERLINK(\"{0}\")", filePath);
ws.Cells[rowIndex, 1].Formula = cellFormula;
使用.Hyperlink时出现此问题。如果我改为使用.Formula并用=HYPERLINK Excel公式填充它,则效果很好。我能够使用这种方法创建具有唯一超链接的250k记录。我没有尝试超过25万,但希望它会工作的很好 谢谢你给我指明了正确的方向
/*
This only works with LESS than 65,530 hyperlinks
*/
ws.Cells[rowIndex, 1].StyleName = "HyperLink";
ws.Cells[rowIndex, 1].Hyperlink = new OfficeOpenXml.ExcelHyperLink(fullFilePath, ExcelHyperLink.UriSchemeFile);
ws.Cells[rowIndex, 1].Value = fullFilePath;
/*
This works with more that 65,530 hyperlinks
*/
string cellFormula = string.Format("=HYPERLINK(\"{0}\")", filePath);
ws.Cells[rowIndex, 1].Formula = cellFormula;
哇!我将尝试提出一种不同的方法。谢谢!我将尝试提出一种不同的方法。谢谢