2017-09-05 118 views
0

书面当我尝试写由EPPlus给出的方法的东西,即它有两个错误消息当打开Excel时出现错误消息与epplus

来了,我们已经找到了一些内容的问题出现了

Excel完成文件级别验证和修复。此工作簿的某些部分可能已被修复或丢弃。

Excel打开成功,但有错误信息,还有一件事我写的Excel已写入,这意味着它是一个模板。

Dim consh As ExcelWorksheet 
    'Dim excelStream As New MemoryStream() 
    'excelStream.Write(excel, 0, excel.Length) 
    Dim exlpck As New ExcelPackage(excel) 
    If exlpck.Workbook.Worksheets(cellExcelTabName) Is Nothing Then 
     consh = exlpck.Workbook.Worksheets.Add(cellExcelTabName) 
    Else 
     consh = exlpck.Workbook.Worksheets(cellExcelTabName) 
    End If 
    Dim start = consh.Dimension.Start 
    Dim [end] = consh.Dimension.[End] 
    For row As Integer = 4 To [end].Row 
     ' Row by row... 
     For col As Integer = 18 To 35 
      ' ... Cell by cell... 
      ' This got me the actual value I needed. 
      Dim cellValue As String = consh.Cells(row, col).Text 
      Dim cellAddress = consh.Cells(row, col).Address 
      Dim i = 0 
      For Each mText In textToFind 
       If cellValue.Contains(mText) Then 
        consh.Cells(cellAddress).Value = cellValue.Replace(mText, "")[enter image description here][1] 
        consh.Cells(cellAddress).Style.Fill.PatternType = ExcelFillStyle.Solid 
        consh.Cells(cellAddress).Style.Fill.BackgroundColor.SetColor(color(mText.Substring(1, 1) - 1)) 
        i = i + 1 
       End If 
      Next 
     Next 
    Next 
    'Dim exlpck1 As New ExcelPackage(e) 
    exlpck.Save() 
    Dim s = New MemoryStream(exlpck.GetAsByteArray()) 
    Return s 

回答

0

如前所述here(“我得到的Excel发现无法读取内容......一个错误”),该EPPlus包不验证公式和数字格式。你可能想检查提示。

0

我发现修复我的代码

exlpck.Save() 

exlpck.SaveAs(ms) 

被取代,它的工作:)

相关问题