Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No data returned in large xls Excel 97-2003 worksheet #561

Open
CalypsoSys opened this issue Jul 29, 2021 · 4 comments
Open

No data returned in large xls Excel 97-2003 worksheet #561

CalypsoSys opened this issue Jul 29, 2021 · 4 comments

Comments

@CalypsoSys
Copy link

CalypsoSys commented Jul 29, 2021

I have a very large Excep that is read

calling ExcelReaderFactory.CreateReader(stream) works but when I then call reader.Read() no data is returned

Cannot attach file, but it is available on (318 MB)

https://vondavon.com/exceldatareader/vehicles_xls.xls

@andersnm
Copy link
Collaborator

Hi,

Interesting, thank you. The Excep contains a "V4 Macro Sheet", but ExcelDataReader doesn't recognize that and skips it. I can read it after changing certain sheet type checks (and optimizing the cyclic sector check):

image

--- a/src/ExcelDataReader/Core/BinaryFormat/XlsWorkbook.cs
+++ b/src/ExcelDataReader/Core/BinaryFormat/XlsWorkbook.cs
@@ -173,7 +173,7 @@ namespace ExcelDataReader.Core.BinaryFormat
                         InterfaceHdr = hdr;
                         break;
                     case XlsBiffBoundSheet sheet:
-                        if (sheet.Type != XlsBiffBoundSheet.SheetType.Worksheet)
+                        if (sheet.Type != XlsBiffBoundSheet.SheetType.Worksheet && sheet.Type != XlsBiffBoundSheet.SheetType.MacroSheet)
                             break;
                         Sheets.Add(sheet);
                         break;


--- a/src/ExcelDataReader/Core/BinaryFormat/XlsWorksheet.cs
+++ b/src/ExcelDataReader/Core/BinaryFormat/XlsWorksheet.cs
@@ -435,7 +435,7 @@ namespace ExcelDataReader.Core.BinaryFormat
             using (var biffStream = new XlsBiffStream(Stream, (int)DataOffset, Workbook.BiffVersion, null, Workbook.SecretKey, Workbook.Encryption))
             {
                 // Check the expected BOF record was found in the BIFF stream
-                if (biffStream.BiffVersion == 0 || biffStream.BiffType != BIFFTYPE.Worksheet)
+                if (biffStream.BiffVersion == 0 || (biffStream.BiffType != BIFFTYPE.Worksheet && biffStream.BiffType != BIFFTYPE.v4MacroSheet))
                     return;
 
                 XlsBiffHeaderFooterString header = null;


--- a/src/ExcelDataReader/Core/CompoundFormat/CompoundDocument.cs
+++ b/src/ExcelDataReader/Core/CompoundFormat/CompoundDocument.cs
@@ -75,12 +75,19 @@ namespace ExcelDataReader.Core.CompoundFormat
         internal List<uint> GetSectorChain(uint sector, List<uint> sectorTable)
         {
             List<uint> chain = new List<uint>();
+#if !NET20
+            HashSet<uint> uniq = new HashSet<uint>();
+#endif
             while (sector != (uint)FATMARKERS.FAT_EndOfChain)
             {
                 chain.Add(sector);
                 sector = GetNextSector(sector, sectorTable);
 
+#if !NET20
+                if (!uniq.Add(sector))
+#else
                 if (chain.Contains(sector))
+#endif
                 {
                     throw new CompoundDocumentException(Errors.ErrorCyclicSectorChain);
                 }

@CalypsoSys
Copy link
Author

thanks!

I will build locally and apply fix. Will this get rolled into a distributed release or would you recommend forking and merge with changes with main branches?

@andersnm
Copy link
Collaborator

andersnm commented Aug 3, 2021

Hi, I'm sure this will be fixed at some point, but I cannot give an ETA. I'd like to familiarize myself with these "Macro Sheets" a bit more - f.ex can we assume to treat them as regular sheets? Maybe they should always be last? Until then, to progress I recommend to patch the latest develop branch and use that. The latest prerelease nuget was built from the latest develop branch.

@CalypsoSys
Copy link
Author

thank you very much - this library is great, in my tests so much faster than the alternatives for read-only operations and easy to use!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants