This project has moved and is read-only. For the latest updates, please go here.

AddComment issue with EpPlus 4.0 Beta DLL

Apr 7, 2014 at 3:38 PM
Hi,
We have a problem to add comments to cells with the EPPLUS 4.0 Beta library.
After adding comments, the saving file generate a streaming exception.
the exception message is : Memory stream is not expandable.
NB: we used the FileInfo class
this issue is not appearing with the 3.1 build
we can't use the 3.1 build because there is an issue when using it in an ACCESS application.
best regards
Apr 9, 2014 at 11:40 AM
Hi,
I havn't seen this behaviour.
Please add an issue with some code to reproduce this problem, so I can have a look at it.
Apr 10, 2014 at 12:19 PM
hello,
the problem is solved.
we have two excel WorkSheets. the first is used to extract the comments and we want copied into the second one.
with the EPPLUS 4.0 Library, if we run this code:

  Dim dicToolTip As Dictionary(Of String, String) = Nothing
        Using pck As New ExcelPackage(New FileInfo(My.Application.Info.DirectoryPath & "\TestComment.xlsx"))
            Dim ws1 = pck.Workbook.Worksheets(1)
            Dim IMyLastColFirstWs = ws1.Cells.AsEnumerable.Where(Function(f) f.Value = "MyCol").Select(Function(f) f.Start.Column).FirstOrDefault
            Dim rngToolTip = ws1.Cells(1, 1, 1, IMyLastColFirstWs)
            dicToolTip = rngToolTip.ToDictionary(Function(f) f.Value.ToString, Function(f) f.Comment.Text)
            Dim ws = pck.Workbook.Worksheets(2)
            Dim iMyLastColSecondWs = ws.Cells.AsEnumerable.Where(Function(f) f.Value = "MyCol").Select(Function(f) f.Start.Column).Max
            Dim rng = ws.Cells(1, 1, 1, iMyLastColSecondWs)
            Dim i = 1
            For Each c In rng
                If c.Value IsNot Nothing Then
                    Dim cellComment As String = Nothing
                    If dicToolTip.TryGetValue(c.Value, cellComment) Then
                        c.AddComment(cellComment, Nothing)
                        c.Comment.AutoFit = True
                    End If
                End If
            Next
            Dim fi = New FileInfo(My.Application.Info.DirectoryPath & "\TestComment_After.xlsx")
            If fi.Exists Then fi.Delete()
            pck.SaveAs(fi)
        End Using
we have the exception message : Memory stream is not expandable.

But if we run this code:

 Dim dicToolTip As Dictionary(Of String, String) = Nothing
 
            Using pck As New ExcelPackage(New FileInfo(My.Application.Info.DirectoryPath & "\TestComment.xlsx"))
                Dim ws1 = pck.Workbook.Worksheets(1)
                Dim IMyLastColFirstWs = ws1.Cells.AsEnumerable.Where(Function(f) f.Value = "MyCol").Select(Function(f) f.Start.Column).FirstOrDefault
                Dim rngToolTip = ws1.Cells(1, 1, 1, IMyLastColFirstWs)
                dicToolTip = rngToolTip.ToDictionary(Function(f) f.Value.ToString, Function(f) f.Comment.Text)
            End Using
            
            Using pck1 As New ExcelPackage(New FileInfo(My.Application.Info.DirectoryPath & "\TestComment.xlsx"))
                Dim ws = pck1.Workbook.Worksheets(2)
                Dim iMyLastColSecondWs = ws.Cells.AsEnumerable.Where(Function(f) f.Value = "MyCol").Select(Function(f) f.Start.Column).Max
                Dim rng = ws.Cells(1, 1, 1, iMyLastColSecondWs)
                Dim i = 1
                For Each c In rng
                    If c.Value IsNot Nothing Then
                        Dim cellComment As String = Nothing
                        If dicToolTip.TryGetValue(c.Value, cellComment) Then
                            c.AddComment(cellComment, Nothing)
                            c.Comment.AutoFit = True
                        End If
                    End If
                Next
                Dim fi = New FileInfo(My.Application.Info.DirectoryPath & "\TestComment_After.xlsx")
                If fi.Exists Then fi.Delete()
                pck1.SaveAs(fi)
            End Using
Everything is now ok.

NB: with the first code we do not have the exception message with the 3.1 version.