Example #1
7
 private void newNToolStripMenuItem_Click(object sender, EventArgs e)
 {
     //test create xls file
     string file = "C:\\newdoc.xls";
     Workbook workbook = new Workbook();
     Worksheet worksheet = new Worksheet("First Sheet");
     worksheet.Cells[0, 1] = new Cell((short)1);
     worksheet.Cells[2, 0] = new Cell(2.8);
     worksheet.Cells[3, 3] = new Cell((decimal)3.45);
     worksheet.Cells[2, 2] = new Cell("Text string");
     worksheet.Cells[2, 4] = new Cell("Second string");
     worksheet.Cells[4, 0] = new Cell(32764.5, "#,##0.00");
     worksheet.Cells[5, 1] = new Cell(DateTime.Now, @"YYYY\-MM\-DD");
     worksheet.Cells.ColumnWidth[0, 1] = 3000;
     //Picture pic = new Picture();
     //pic.Image = Excel.Image.FromFile("C:\\DelBreakpoint.png");
     //pic.TopLeftCorner = new CellAnchor(5, 1, 0, 0);
     //pic.BottomRightCorner = new CellAnchor(12, 5, 592, 243);
     //worksheet.AddPicture(pic);
     workbook.Worksheets.Add(worksheet);
     workbook.Save(file);
     //open created file
     doc = CompoundDocument.Open(file);
     IsOpened = true;
     PopulateTreeview(file);
 }
 public MasterSectorAllocation(CompoundDocument document)
 {
     this.Document = document;
     this.NumberOfSecIDs = document.Header.NumberOfSATSectors;
     this.CurrentMSATSector = document.Header.FirstSectorIDofMasterSectorAllocationTable;
     this.SecIDCapacity = document.SectorSize / 4 - 1;
     InitializeMasterSectorAllocationTable();
 }
Example #3
0
 public static CompoundDocument Create(Stream stream)
 {
     CompoundDocument document = new CompoundDocument(stream, new CompoundFileHeader());
     document.WriteHeader();
     document.MasterSectorAllocation.AllocateSATSector();
     document.InitializeDirectoryEntries();
     return document;
 }
 public static CompoundDocument Create(string file)
 {
     FileStream stream = File.Open(file, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
     CompoundDocument document = new CompoundDocument(stream, new CompoundFileHeader());
     document.WriteHeader();
     document.MasterSectorAllocation.AllocateSATSector();
     document.InitializeDirectoryEntries();
     return document;
 }
 public ShortSectorAllocation(CompoundDocument document)
 {
     this.Document = document;
     ShortSectorAllocationTable = document.GetStreamDataAsIntegers(document.Header.FirstSectorIDofShortSectorAllocationTable);
     //ShortSectorAllocationTable.RemoveRange(document.Header.NumberOfShortSectors, ShortSectorAllocationTable.Count - document.Header.NumberOfShortSectors);
     while (ShortSectorAllocationTable.Count > 0 && ShortSectorAllocationTable[ShortSectorAllocationTable.Count - 1] == SID.Free)
     {
         ShortSectorAllocationTable.RemoveAt(ShortSectorAllocationTable.Count - 1);
     }
 }
Example #6
0
        public static CompoundDocument Open(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);
            FileHeader header = ReadHeader(reader);

            CompoundDocument document = new CompoundDocument(stream, header);
            if (!document.CheckHeader()) return null;

            document.ReadDirectoryEntries();

            return document;
        }
        public static CompoundDocument Open(string file)
        {
            FileStream stream = File.Open(file, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
            BinaryReader reader = new BinaryReader(stream);
            FileHeader header = ReadHeader(reader);

            CompoundDocument document = new CompoundDocument(stream, header);
            if (!document.CheckHeader()) return null;

            document.ReadDirectoryEntries();

            return document;
        }
Example #8
0
 private void openOToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         string xlsfilter = "Excel files(*.xls)|*.xls|All files (*.*)|*.*";
         string file = FileSelector.BrowseFile(xlsfilter);
         if (file == null) return;
         doc = CompoundDocument.Open(file);
         IsOpened = true;
         PopulateTreeview(file);
     }
     catch (Exception error)
     {
         MessageBox.Show(error.Message);
     }
 }
Example #9
0
        public static CompoundDocument Open(string file)
        {
            FileStream       fileStream       = File.Open(file, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
            BinaryReader     reader           = new BinaryReader(fileStream);
            FileHeader       header           = CompoundDocument.ReadHeader(reader);
            CompoundDocument compoundDocument = new CompoundDocument(fileStream, header);
            CompoundDocument result;

            if (!compoundDocument.CheckHeader())
            {
                result = null;
            }
            else
            {
                compoundDocument.ReadDirectoryEntries();
                result = compoundDocument;
            }
            return(result);
        }
Example #10
0
 public void Save()
 {
     if (ShortSectorAllocationTable.Count > 0)
     {
         if (Document.Header.FirstSectorIDofShortSectorAllocationTable == SID.EOC)
         {
             int   SecIDCapacity = Document.SectorSize / 4;
             int[] sids          = new Int32[SecIDCapacity];
             for (int i = 0; i < sids.Length; i++)
             {
                 sids[i] = SID.Free;
             }
             Document.Header.FirstSectorIDofShortSectorAllocationTable = Document.AllocateDataSector();
             Document.WriteInSector(Document.Header.FirstSectorIDofShortSectorAllocationTable, 0, sids);
         }
         MemoryStream satStream = new MemoryStream(ShortSectorAllocationTable.Count * 4);
         CompoundDocument.WriteArrayOfInt32(new BinaryWriter(satStream), ShortSectorAllocationTable.ToArray());
         Document.WriteStreamData(Document.Header.FirstSectorIDofShortSectorAllocationTable, satStream.ToArray());
     }
 }
Example #11
0
 private static void WriteHeader(BinaryWriter writer, FileHeader header)
 {
     writer.Write(header.FileTypeIdentifier);
     writer.Write(header.FileIdentifier.ToByteArray());
     writer.Write(header.RevisionNumber);
     writer.Write(header.VersionNumber);
     writer.Write(header.ByteOrderMark);
     writer.Write(header.SectorSizeInPot);
     writer.Write(header.ShortSectorSizeInPot);
     writer.Write(header.UnUsed10);
     writer.Write(header.NumberOfSATSectors);
     writer.Write(header.FirstSectorIDofDirectoryStream);
     writer.Write(header.UnUsed4);
     writer.Write(header.MinimumStreamSize);
     writer.Write(header.FirstSectorIDofShortSectorAllocationTable);
     writer.Write(header.NumberOfShortSectors);
     writer.Write(header.FirstSectorIDofMasterSectorAllocationTable);
     writer.Write(header.NumberOfMasterSectors);
     CompoundDocument.WriteArrayOfInt32(writer, header.MasterSectorAllocationTable);
 }
Example #12
0
 public void Save()
 {
     checked
     {
         if (this.ShortSectorAllocationTable.Count > 0)
         {
             if (this.Document.Header.FirstSectorIDofShortSectorAllocationTable == -2)
             {
                 int   num   = this.Document.SectorSize / 4;
                 int[] array = new int[num];
                 for (int i = 0; i < array.Length; i++)
                 {
                     array[i] = -1;
                 }
                 this.Document.Header.FirstSectorIDofShortSectorAllocationTable = this.Document.AllocateDataSector();
                 this.Document.WriteInSector(this.Document.Header.FirstSectorIDofShortSectorAllocationTable, 0, array);
             }
             MemoryStream memoryStream = new MemoryStream(this.ShortSectorAllocationTable.Count * 4);
             CompoundDocument.WriteArrayOfInt32(new BinaryWriter(memoryStream), this.ShortSectorAllocationTable.ToArray());
             this.Document.WriteStreamData(this.Document.Header.FirstSectorIDofShortSectorAllocationTable, memoryStream.ToArray());
         }
     }
 }
Example #13
0
 private static FileHeader ReadHeader(BinaryReader reader)
 {
     return(new FileHeader
     {
         FileTypeIdentifier = reader.ReadBytes(8),
         FileIdentifier = new Guid(reader.ReadBytes(16)),
         RevisionNumber = reader.ReadUInt16(),
         VersionNumber = reader.ReadUInt16(),
         ByteOrderMark = reader.ReadBytes(2),
         SectorSizeInPot = reader.ReadUInt16(),
         ShortSectorSizeInPot = reader.ReadUInt16(),
         UnUsed10 = reader.ReadBytes(10),
         NumberOfSATSectors = reader.ReadInt32(),
         FirstSectorIDofDirectoryStream = reader.ReadInt32(),
         UnUsed4 = reader.ReadBytes(4),
         MinimumStreamSize = reader.ReadInt32(),
         FirstSectorIDofShortSectorAllocationTable = reader.ReadInt32(),
         NumberOfShortSectors = reader.ReadInt32(),
         FirstSectorIDofMasterSectorAllocationTable = reader.ReadInt32(),
         NumberOfMasterSectors = reader.ReadInt32(),
         MasterSectorAllocationTable = CompoundDocument.ReadArrayOfInt32(reader, 109)
     });
 }
Example #14
0
 public SectorAllocation(CompoundDocument document)
 {
     this.Document      = document;
     this.SecIDCapacity = document.SectorSize / 4;
 }
Example #15
0
 public DirectoryEntry(CompoundDocument document, string name)
     : this(name)
 {
     Document = document;
 }
Example #16
0
 private void WriteHeader()
 {
     this.FileStorage.Position = 0L;
     CompoundDocument.WriteHeader(this.Writer, this.Header);
 }
Example #17
0
        private void _treeViewProjectExplore_DoubleClick(object sender, EventArgs e)
        {
            tabControl1X.SelectedIndex = 2;
            if (_treeViewProjectExplore.SelectedNode.Name == "File")
            {
                try
                {
                    LoadExcelSheets();
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("Error opening the excel file." + Environment.NewLine +
                      ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            //Open file excel
            string fName = _treeViewProjectExplore.Nodes[0].Tag + @"\" + _treeViewProjectExplore.Nodes[0].Nodes[0].Text + @"\" + _treeViewProjectExplore.SelectedNode.Text;
            string fName1 = _treeViewProjectExplore.Nodes[0].Tag + @"\" + _treeViewProjectExplore.Nodes[0].Nodes[1].Text + @"\" + _treeViewProjectExplore.SelectedNode.Text;
            string fName2 = _treeViewProjectExplore.Nodes[0].Tag + @"\" + _treeViewProjectExplore.Nodes[0].Nodes[2].Text + @"\" + _treeViewProjectExplore.SelectedNode.Text;

            if (_treeViewProjectExplore.SelectedNode.Text == _treeViewProjectExplore.SelectedNode.Text)
            {
                try
                {
                    doc = CompoundDocument.Open(fName);
                    LoadExcelSheets();
                }
                catch (Exception ex)
                {

                }
                if (_treeViewProjectExplore.SelectedNode.Text == _treeViewProjectExplore.SelectedNode.Text)
                {
                    try
                    {
                        doc = CompoundDocument.Open(fName1);
                        LoadExcelSheets();
                    }
                    catch (Exception ex)
                    {

                    }
                }
                if (_treeViewProjectExplore.SelectedNode.Text == _treeViewProjectExplore.SelectedNode.Text)
                {
                    try
                    {
                        doc = CompoundDocument.Open(fName2);
                        LoadExcelSheets();
                    }
                    catch (Exception ex)
                    {

                    }
                }
            }
        }
Example #18
0
        private void addFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _frmNewFile newFile = new _frmNewFile();
            newFile.ShowDialog();

            Excel.Application xlApp = default(Excel.Application);
            Excel.Workbook xlWorkBook = default(Excel.Workbook);
            Excel.Worksheet xlWorkSheet = default(Excel.Worksheet);

            TreeNode treeNode = new TreeNode();
            treeNode.Text = newFile.textBoxName.Text + "." + newFile.comboBoxType.Text;
            treeNode.Tag = treeNode.Text;
            treeNode.Name = "File";
            treeNode.ImageIndex = newFile.comboBoxType.SelectedIndex;
            newFile.Close();
            if (newFile.textBoxName.Text != "")
            {
                _treeViewProjectExplore.SelectedNode.Nodes.Add(treeNode);
                _treeViewProjectExplore.SelectedNode.ExpandAll();

                string fName = _treeViewProjectExplore.Nodes[0].Tag + @"\" + _treeViewProjectExplore.SelectedNode.Tag + @"\" + treeNode.Tag;
                try
                {
                    object misValue = System.Reflection.Missing.Value;
                    xlApp = new Excel.Application();
                    xlWorkBook = xlApp.Workbooks.Add(misValue);
                    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                    xlWorkBook.SaveAs(fName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                    xlWorkBook.Close(true, misValue, misValue);
                    xlApp.Quit();
                    releaseObject(xlWorkSheet);
                    releaseObject(xlWorkBook);
                    releaseObject(xlApp);
                }
                finally
                {
                    if (xlApp != null)
                        releaseObject(xlApp);
                    if (xlWorkBook != null)
                        releaseObject(xlWorkBook);
                    if (xlWorkSheet != null)
                        releaseObject(xlWorkSheet);
                }
                if (System.IO.File.Exists(fName))
                {
                    //if (System.Windows.Forms.MessageBox.Show("Would you like to open the excel file?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    //{
                    //    try
                    //    {
                    //        //System.Diagnostics.Process.Start(fName);
                    doc = CompoundDocument.Open(fName);
                    //        LoadExcel();

                    //    }
                    //    catch (Exception ex)
                    //    {
                    //        System.Windows.Forms.MessageBox.Show("Error opening the excel file." + Environment.NewLine +
                    //          ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //    }
                    //} //doc1 = CompoundDocument.Open(fName);
                }
            }
        }
Example #19
0
 //------------------------------------------------------------------------------------
 public string getopen(string path)
 {
     try
     {
         string file = path;
         doc = CompoundDocument.Open(file);
         return file;
     }
     catch(Exception e)
     {
         return "";
         MessageBox.Show(""+ e);
     }
 }
Example #20
0
        private void addFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _frmNewFile newFile = new _frmNewFile();
            newFile.Text = _treeViewProjectExplore.SelectedNode.Text + " - " + newFile.Text;
            newFile.ShowDialog();

            Excel.Application xlApp = default(Excel.Application);
            Excel.Workbook xlWorkBook = default(Excel.Workbook);
            //TabPage sheetPage = new TabPage(_treeViewProjectExplore.SelectedNode.Text);
            //Excel.Worksheet xlWorkSheet = default(Excel.Worksheet);
            Excel.Worksheet xlWorkSheet = new Excel.Worksheet();

            TreeNode treeNode = new TreeNode();
            treeNode.Text = newFile.textBoxName.Text + "." + newFile.comboBoxType.Text;
            treeNode.Tag = treeNode.Text;
            treeNode.Name = "File";
            treeNode.ImageIndex = newFile.comboBoxType.SelectedIndex;
            newFile.Close();
            if (newFile.textBoxName.Text != "")
            {
                _treeViewProjectExplore.SelectedNode.Nodes.Add(treeNode);
                _treeViewProjectExplore.SelectedNode.ExpandAll();

                string fName = _treeViewProjectExplore.Nodes[0].Tag + @"\" + _treeViewProjectExplore.SelectedNode.Tag + @"\" + treeNode.Tag;
                try
                {
                    object misValue = System.Reflection.Missing.Value;
                    xlApp = new Excel.Application();
                    xlWorkBook = xlApp.Workbooks.Add(misValue);
                    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                    xlWorkBook.SaveAs(fName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                    xlWorkBook.Close(true, misValue, misValue);
                    xlApp.Quit();
                    releaseObject(xlWorkSheet);
                    releaseObject(xlWorkBook);
                    releaseObject(xlApp);
                }
                finally
                {
                    if (xlApp != null)
                        releaseObject(xlApp);
                    if (xlWorkBook != null)
                        releaseObject(xlWorkBook);
                    if (xlWorkSheet != null)
                        releaseObject(xlWorkSheet);
                }
                if (System.IO.File.Exists(fName))
                {
                    doc = CompoundDocument.Open(fName);
                }

            }
        }
 public SectorAllocation(CompoundDocument document)
 {
     this.Document = document;
     this.SecIDCapacity = document.SectorSize / 4;
 }