示例#1
0
        public static ExcelXmlWorkbook Import(string string_0)
        {
            ExcelXmlWorkbook workbook;

            if (!File.Exists(string_0))
            {
                return(null);
            }
            try
            {
                Stream           stream    = new FileStream(string_0, FileMode.Open, FileAccess.Read);
                ExcelXmlWorkbook workbook2 = Import(stream);
                stream.Close();
                stream.Dispose();
                return(workbook2);
            }
            catch (IOException)
            {
                workbook = null;
            }
            catch (SecurityException)
            {
                workbook = null;
            }
            catch (UnauthorizedAccessException)
            {
                workbook = null;
            }
            return(workbook);
        }
示例#2
0
 internal Column(Worksheet worksheet_0)
 {
     if (worksheet_0 == null)
     {
         throw new ArgumentNullException("parent");
     }
     this.excelXmlWorkbook_0 = worksheet_0.excelXmlWorkbook_0;
 }
示例#3
0
        public static ExcelXmlWorkbook DataSetToWorkbook(DataSet dataSet_0)
        {
            ExcelXmlWorkbook workbook = new ExcelXmlWorkbook();

            for (int i = 0; i < dataSet_0.Tables.Count; i++)
            {
                Worksheet worksheet = workbook[i];
                worksheet.Name = "Table" + i.ToString(CultureInfo.InvariantCulture);
                int count = dataSet_0.Tables[i].Columns.Count;
                for (int j = 0; j < count; j++)
                {
                    worksheet[j, 0].Value     = dataSet_0.Tables[i].Columns[j].ColumnName;
                    worksheet[j, 0].Font.Bold = true;
                }
                int num2 = 0;
                foreach (DataRow row in dataSet_0.Tables[i].Rows)
                {
                    num2++;
                    for (int k = 0; k < count; k++)
                    {
                        switch (row[k].GetType().FullName)
                        {
                        case "System.DateTime":
                            worksheet[k, num2].Value = (DateTime)row[k];
                            break;

                        case "System.Boolean":
                            worksheet[k, num2].Value = (bool)row[k];
                            break;

                        case "System.SByte":
                        case "System.Int16":
                        case "System.Int32":
                        case "System.Int64":
                        case "System.Byte":
                        case "System.UInt16":
                        case "System.UInt32":
                        case "System.UInt64":
                        case "System.Single":
                        case "System.Double":
                        case "System.Decimal":
                            worksheet[k, num2].Value = Convert.ToDecimal(row[k], CultureInfo.InvariantCulture);
                            break;

                        case "System.DBNull":
                            break;

                        default:
                            worksheet[k, num2].Value = row[k].ToString();
                            break;
                        }
                    }
                }
            }
            return(workbook);
        }
示例#4
0
 internal void method_5(XmlReader xmlReader_0)
 {
     foreach (XmlReaderAttributeItem item in xmlReader_0.GetAttributes())
     {
         if ((item.LocalName == "Name") && item.HasValue)
         {
             this.Name = item.Value;
         }
         if ((item.LocalName == "StyleID") && item.HasValue)
         {
             base.Style = this.excelXmlWorkbook_0.method_6(item.Value);
         }
     }
     while (xmlReader_0.Read())
     {
         string str;
         if ((xmlReader_0.Name == "Worksheet") && (xmlReader_0.NodeType == XmlNodeType.EndElement))
         {
             break;
         }
         if ((xmlReader_0.NodeType == XmlNodeType.Element) && ((str = xmlReader_0.Name) != null))
         {
             if (str != "Names")
             {
                 if (!(str == "Table"))
                 {
                     if (str == "WorksheetOptions")
                     {
                         this.method_6(xmlReader_0);
                     }
                 }
                 else
                 {
                     this.method_9(xmlReader_0);
                 }
             }
             else
             {
                 ExcelXmlWorkbook.smethod_0(xmlReader_0, this.vmethod_0().list_2, this);
             }
         }
     }
 }
示例#5
0
 internal Worksheet(ExcelXmlWorkbook excelXmlWorkbook_1)
 {
     if (excelXmlWorkbook_1 == null)
     {
         throw new ArgumentNullException("parent");
     }
     this.excelXmlWorkbook_0       = excelXmlWorkbook_1;
     this.PrintOptions             = new Aisino.Framework.Plugin.Core.ExcelXml.PrintOptions();
     this.PrintOptions.Layout      = PageLayout.None;
     this.PrintOptions.Orientation = PageOrientation.None;
     this.list_1             = new List <Row>();
     this.list_0             = new List <Column>();
     this.list_2             = new List <Aisino.Framework.Plugin.Core.ExcelXml.Range>();
     this.TabColor           = -1;
     this.PrintOptions.int_1 = 1;
     this.PrintOptions.int_2 = 1;
     this.PrintOptions.int_0 = 100;
     this.PrintOptions.ResetMargins();
 }
示例#6
0
        public void ConvertToExcel(string string_0, string string_1)
        {
            int rowCount    = this.dataGridView_0.RowCount;
            int columnCount = this.dataGridView_0.ColumnCount;

            if ((rowCount <= 0) || (columnCount <= 0))
            {
                this.ExportEndedEvent(new object(), new ExportEndedEventArgs(false, new Exception("No data for exporting.")));
            }
            else if (rowCount > 0x10000)
            {
                this.ExportEndedEvent(new object(), new ExportEndedEventArgs(false, new Exception("The rows count should be less than or equal to 65536.")));
            }
            else if (columnCount > 0xff)
            {
                this.ExportEndedEvent(new object(), new ExportEndedEventArgs(false, new Exception("The columns count should be less than or equal to 255.")));
            }
            else
            {
                if (File.Exists(string_0))
                {
                    try
                    {
                        File.Delete(string_0);
                    }
                    catch (Exception exception2)
                    {
                        this.ExportEndedEvent(new object(), new ExportEndedEventArgs(false, new Exception(string.Format("Cannot delete the file\r\n{0}", exception2.Message))));
                        return;
                    }
                }
                this.ExportStartingEvent(columnCount + rowCount, new EventArgs());
                ExcelXmlWorkbook workbook = new ExcelXmlWorkbook {
                    Properties = { Author = "航天信息股份有限公司" }
                };
                Worksheet worksheet = workbook[0];
                if (string.Empty.Equals(string_1))
                {
                    worksheet.Name = "防伪开票系统导出报表";
                }
                else
                {
                    worksheet.Name = string_1;
                }
                try
                {
                    worksheet.FreezeTopRows = 1;
                    int num3 = 1;
                    for (int i = 0; i <= (columnCount - 1); i++)
                    {
                        if (this.dataGridView_0.Columns[i].Visible)
                        {
                            worksheet[num3 - 1, 0].Value = this.dataGridView_0.Columns[i].HeaderText.Trim();
                            num3++;
                        }
                        this.ExportProgressingEvent(i + 1, new EventArgs());
                    }
                    new Range(worksheet[0, 0], worksheet[columnCount - 1, 0]).Font.Bold = true;
                    int num5 = 0;
Label_01B7:
                    if (num5 <= (rowCount - 1))
                    {
                        num3 = 1;
                        int num6 = 0;
                        while (true)
                        {
                            if (num6 < columnCount)
                            {
                                if (this.dataGridView_0.Columns[num6].Visible)
                                {
                                    try
                                    {
                                        worksheet[num3 - 1, num5 + 1].Value = this.dataGridView_0.Rows[num5].Cells[num6].Value.ToString().Trim();
                                        num3++;
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                            else
                            {
                                this.ExportProgressingEvent((columnCount + num5) + 1, new EventArgs());
                                num5++;
                                goto Label_01B7;
                            }
                            num6++;
                        }
                    }
                    workbook.Export(string_0);
                }
                catch (Exception exception)
                {
                    this.ExportEndedEvent(new object(), new ExportEndedEventArgs(false, new Exception(string.Format("Export file failed.\r\n{0}", exception.Message))));
                    return;
                }
                finally
                {
                    GC.Collect();
                }
                this.ExportEndedEvent(new object(), new ExportEndedEventArgs(true, null));
            }
        }