コード例 #1
0
        private void WriteOutput(object sender, RoutedEventArgs e)
        {
            // Get the output file name from the text box.
            string fileName = this.outputTextBox.Text;

            if (ReadInput2_sub() == false)
            {
                return;
            }

            if (ReadInput_sub() == false)
            {
                return;
            }

            // Delete contents of the temporary directory.
            XlsxRW.DeleteDirectoryContents(tempDir);

            // Unzip AMC Roster XLSX file to the temporary directory.
            bool ret = XlsxRW.UnzipFile(this.inputTextBox2.Text, tempDir);

            if (ret == false)
            {
                return;
            }
            // We will need two string tables; a lookup IDictionary<string, int> for fast searching and
            // an ordinary IList<string> where items are sorted by their index.
            IDictionary <string, int> lookupTable;

            // Call helper methods which creates both tables from input data.
            var stringTable = XlsxRW.CreateStringTables(this.data, out lookupTable);

            // Create XML file..
            using (var stream = new FileStream(Path.Combine(tempDir, @"xl\sharedStrings.xml"),
                                               FileMode.Create))
                // ..and fill it with unique strings used in the workbook
                XlsxRW.WriteStringTable(stream, stringTable);

            // Create XML file..
            using (var stream = new FileStream(Path.Combine(tempDir, @"xl\worksheets\sheet1.xml"),
                                               FileMode.Create))
                // ..and fill it with rows and columns of the DataTable.
                XlsxRW.WriteWorksheet(stream, this.data, lookupTable);

            // ZIP temporary directory to the XLSX file.
            ret = XlsxRW.ZipDirectory(tempDir, fileName);
            if (ret == false)
            {
                return;
            }

            // If checkbox is checked, show XLSX file in Microsoft Excel.
            if (this.openFileCheckBox.IsChecked == true)
            {
                System.Diagnostics.Process.Start(fileName);
            }
        }
コード例 #2
0
        private bool ReadInput_sub()
        {
            // Get the input file name from the text box.
            var fileName = this.inputTextBox.Text;

            // Delete contents of the temporary directory.
            XlsxRW.DeleteDirectoryContents(tempDir);

            if (!(File.Exists(fileName)))
            {
                System.Windows.Forms.MessageBox.Show("Invalid File Chosen (State): " + fileName,
                                                     "Invalid File",
                                                     System.Windows.Forms.MessageBoxButtons.OK,
                                                     System.Windows.Forms.MessageBoxIcon.Exclamation,
                                                     System.Windows.Forms.MessageBoxDefaultButton.Button1);
                return(false);
            }

            // Unzip input XLSX file to the temporary directory.
            bool ret = XlsxRW.UnzipFile(fileName, tempDir);

            if (ret == false)
            {
                return(false);
            }

            IList <string> stringTable;

            // Open XML file with table of all unique strings used in the workbook..
            using (var stream = new FileStream(Path.Combine(tempDir, @"xl\sharedStrings.xml"),
                                               FileMode.Open, FileAccess.Read))
                // ..and call helper method that parses that XML and returns an array of strings.
                stringTable = XlsxRW.ReadStringTable(stream);

            // Open XML file with worksheet data..
            using (var stream = new FileStream(Path.Combine(tempDir, @"xl\worksheets\sheet1.xml"),
                                               FileMode.Open, FileAccess.Read))
                // ..and call helper method that parses that XML and fills DataTable with values.
                XlsxRW.ReadWorksheet(stream, stringTable, this.data);

            return(true);
        }