Exemple #1
0
        private static void SaveLowLevelXML(AbsXLSRecords records, string fileName, string sourceFileName)
        {
            StreamWriter writer = new StreamWriter(fileName);

            if (sourceFileName != null)
            {
                writer.WriteLine("<!-- FileName: {0} -->", sourceFileName);
            }
            writer.WriteLine("<ExcelFile>");
            string name  = null;
            int    index = 0;

            foreach (AbsXLSRec rec in records)
            {
                if (rec.Name == name)
                {
                    index++;
                }
                else
                {
                    index = 0;
                    name  = rec.Name;
                }
                writer.WriteLine(rec.GetXMLRecord(index));
            }
            writer.Write("</ExcelFile>");
            writer.Close();
        }
Exemple #2
0
 private void SaveNotes(AbsXLSRecords records)
 {
     for (int i = 0; i < this.notes.Count; i++)
     {
         NoteRecord record = (NoteRecord)this.notes[i];
         records.Add(record);
     }
 }
Exemple #3
0
        public void LoadXls(Stream stream, XlsOptions xlsOptions)
        {
            this.FileName = "Stream";
            this.Reset();
            AbsXLSRecords records = ReadStreamHelper(this, stream, (xlsOptions & XlsOptions.PreserveSummaries) != XlsOptions.None, ref this.summaryStream, ref this.documentSummaryStream, ref this.macrosesStream);

            this.FillChachedMsoRecords(records);
            new XLSFileReader(this, xlsOptions, this.FileName).ImportRecords(records, this.FileName);
        }
Exemple #4
0
        private void SaveMsoDrawing(AbsXLSRecords records, MsoContainerRecord dgContainer)
        {
            XLSRecord         record;
            MsoDelayedRecords delayedRecords = new MsoDelayedRecords
            {
                Offset = 8
            };

            byte[] sourceArray = dgContainer.ConvertToBytes(delayedRecords);
            sourceArray[0] = 15;
            int sourceIndex = 0;

            if (delayedRecords.Lengths.Count > 0)
            {
                int num2  = 0;
                int count = delayedRecords.Lengths.Count;
                while (num2 < count)
                {
                    int       num4             = (int)delayedRecords.Lengths[num2];
                    ArrayList list             = (ArrayList)delayedRecords.DelayedRecords[num2];
                    int       length           = num4 - sourceIndex;
                    byte[]    destinationArray = new byte[length];
                    Array.Copy(sourceArray, sourceIndex, destinationArray, 0, length);
                    new OptimizedBuffer();
                    if (num4 > 8224)
                    {
                        MemoryStream input = new MemoryStream();
                        input.Write(BitConverter.GetBytes((ushort)length), 0, 2);
                        input.Write(destinationArray, 2, destinationArray.Length);
                        input.Position = 0L;
                        record         = new XLSRecord(60, destinationArray.Length + 2, new BinaryReader(input));
                        input.Close();
                    }
                    else
                    {
                        record = new MsoDrawingRecord();
                        (record as MsoDrawingRecord).Data = destinationArray;
                    }
                    sourceIndex = num4;
                    records.Add(record);
                    for (int i = 0; i < list.Count; i++)
                    {
                        XLSRecord record2 = (XLSRecord)list[i];
                        records.Add(record2);
                    }
                    num2++;
                }
            }
            else
            {
                record = new MsoDrawingRecord();
                (record as MsoDrawingRecord).Data = sourceArray;
                records.Add(record);
            }
        }
Exemple #5
0
        public static void DumpToLowLevelXml(string sourceFileName, string destinationFileName)
        {
            byte[]        ss      = null;
            AbsXLSRecords records = null;

            using (FileStream stream = new FileStream(sourceFileName, FileMode.Open))
            {
                records = ReadStreamHelper(null, stream, false, ref ss, ref ss, ref ss);
            }
            SaveLowLevelXML(records, destinationFileName, sourceFileName);
        }
Exemple #6
0
        public void WriteRecords(AbsXLSRecords destination, int recordCode)
        {
            ArrayList list = (ArrayList)this.typeGroupedRecords[recordCode];

            if (list != null)
            {
                foreach (XLSRecord record in list)
                {
                    destination.Add(record);
                }
            }
        }
Exemple #7
0
        public void LoadXls(string fileName, XlsOptions xlsOptions)
        {
            this.FileName = fileName;
            this.Reset();
            AbsXLSRecords records = null;

            using (FileStream stream = new FileStream(fileName, FileMode.Open))
            {
                records = ReadStreamHelper(this, stream, (xlsOptions & XlsOptions.PreserveSummaries) != XlsOptions.None, ref this.summaryStream, ref this.documentSummaryStream, ref this.macrosesStream);
            }
            this.FillChachedMsoRecords(records);
            new XLSFileReader(this, xlsOptions, fileName).ImportRecords(records, fileName);
        }
Exemple #8
0
        private static AbsXLSRecords ReadStreamHelper(ExcelFile excelFile, Stream inputStream, bool readSummaryStreams, ref byte[] ss, ref byte[] dss, ref byte[] macroses)
        {
            MemoryStream stream = null;

            using (Ole2CompoundFile file = new Ole2CompoundFile())
            {
                file.Load(inputStream, false);
                foreach (Ole2DirectoryEntry entry in file.Root)
                {
                    Ole2Stream stream2 = entry as Ole2Stream;
                    if (stream2 != null)
                    {
                        string name = stream2.Name;
                        if (name != null)
                        {
                            name = string.IsInterned(name);
                            if (name == "Workbook")
                            {
                                stream = new MemoryStream(stream2.GetData());
                            }
                            else if (name == "\x0005SummaryInformation")
                            {
                                if (readSummaryStreams)
                                {
                                    ss = stream2.GetData();
                                }
                            }
                            else if ((name == "\x0005DocumentSummaryInformation") && readSummaryStreams)
                            {
                                dss = stream2.GetData();
                            }
                        }
                    }
                }
            }
            if (stream == null)
            {
                throw new Exception("Provided file is not a valid BIFF8 file. Only XLS files from Excel 97 and on are supported.");
            }
            AbsXLSRecords records = new AbsXLSRecords();

            using (BinaryReader reader = new BinaryReader(stream, new UnicodeEncoding()))
            {
                records.Read(reader, new IoOperationInfo(excelFile, excelFile.FileName, IoOperation.XlsReading));
            }
            stream.Close();
            return(records);
        }
Exemple #9
0
 private static void SaveXLSInternal(Stream stream, AbsXLSRecords records, byte[] ss, byte[] dss, byte[] macrosesStream, bool hasMacroses)
 {
     using (Ole2CompoundFile file = new Ole2CompoundFile())
     {
         file.Root.AddStream("Workbook", XLSFileWriter.GetStream(records));
         if (ss != null)
         {
             file.Root.AddStream("\x0005SummaryInformation", ss);
         }
         if (dss != null)
         {
             file.Root.AddStream("\x0005DocumentSummaryInformation", dss);
         }
         file.Save(stream);
     }
 }
Exemple #10
0
        private void FillChachedMsoRecords(AbsXLSRecords records)
        {
            //using (
            IEnumerator enumerator = records.GetEnumerator();//)
            {
                AbsXLSRec             current;
                MsoDrawingGroupRecord record;
                while (enumerator.MoveNext())
                {
                    current = (AbsXLSRec)enumerator.Current;
                    if (current.RecordCode == 235)
                    {
                        goto Label_002F;
                    }
                }
                return;

Label_002F:
                record = (MsoDrawingGroupRecord)current;
                this.cachedMsoDrawingGroupArguments = record.arguments;
            }
        }
Exemple #11
0
 public void WriteOnDemand(AbsXLSRecords records)
 {
     if (this.Count != 0)
     {
         MsoContainerRecord dgContainer = ImageRecordsFactory.CreateContainer(MsoType.DgContainer);
         MsofbtDgRecord     item        = new MsofbtDgRecord
         {
             Parent = dgContainer
         };
         MsoContainerRecord record3 = ImageRecordsFactory.CreateContainer(MsoType.SpgrContainer);
         record3.Parent = dgContainer;
         MsoContainerRecord record4 = ImageRecordsFactory.CreateContainer(MsoType.SpContainer);
         record4.Parent = record3;
         MsofbtSpgrRecord record5 = new MsofbtSpgrRecord
         {
             Parent = record4
         };
         uint           shapeId = this.GenerateUniqueShapeId();
         MsofbtSpRecord record6 = new MsofbtSpRecord
         {
             Parent    = record5,
             ShapeId   = shapeId,
             IsTopMost = true
         };
         dgContainer.Add(item);
         dgContainer.Add(record3);
         record3.Add(record4);
         record4.Add(record5);
         record4.Add(record6);
         record4.Parent    = record3;
         shapeId           = this.SaveShapes(record3, shapeId);
         item.ShapesNumber = (uint)(this.Worksheet.Shapes.Count + 1);
         item.LastId       = shapeId;
         this.SaveMsoDrawing(records, dgContainer);
         this.SaveNotes(records);
     }
 }
Exemple #12
0
        public void WriteRecords(AbsXLSRecords destination, string recordName)
        {
            int code = XLSDescriptors.GetByName(recordName).Code;

            this.WriteRecords(destination, code);
        }