コード例 #1
0
ファイル: MappingTest.cs プロジェクト: alex765022/IBN
        private DataSet Parse(string FileName)
        {
            DataSet ds = new DataSet();
            //ds.ReadXmlSchema("price.xsd");

            OleDbConnection cnn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileName + ";Extended Properties=\"Excel 8.0;HDR=Yes\"");

            cnn.Open();
            try
            {
                string[] SheetNames = GetSheetNames(cnn);
                foreach (string SheetName in SheetNames)
                {
                    /*
                     * if (SheetName.EndsWith("$Print_Titles") || SheetName.EndsWith("$Print_Area")
                     || SheetName.EndsWith("$Database") || SheetName.EndsWith("$Criteria")
                     || SheetName.EndsWith("$Data_form") || SheetName.EndsWith("$Sheet_Title"))
                     ||{
                     ||}
                     ||else
                     */
                    if (SheetName.EndsWith("$"))
                    {
                        DataTable table = new DataTable();

                        OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [" + SheetName + "]", cnn);
                        //da.FillSchema(ds, SchemaType.Mapped);
                        da.Fill(table);

                        RemoveEmptyRows(table);

                        if (table.Rows.Count != 0)
                        {
                            ds.Tables.Add(table);
                        }
                    }
                }
            }
            finally
            {
                cnn.Close();
            }
            return(ds);
        }
コード例 #2
0
        public virtual DataSet Parse(string fileName, Stream stream)
        {
            if (stream != null)
            {
                throw new NotSupportedException();
            }
            DataSet ds = new DataSet();

            OleDbConnection cnn = new OleDbConnection(_connectionString.Replace("$1", fileName));

            cnn.Open();
            try
            {
                string[] SheetNames = GetSheetNames(cnn);
                foreach (string SheetName in SheetNames)
                {
                    /*
                     * if (SheetName.EndsWith("$Print_Titles") || SheetName.EndsWith("$Print_Area")
                     || SheetName.EndsWith("$Database") || SheetName.EndsWith("$Criteria")
                     || SheetName.EndsWith("$Data_form") || SheetName.EndsWith("$Sheet_Title"))
                     ||{
                     ||}
                     ||else
                     */
                    if (SheetName.EndsWith("$") || SheetName.IndexOf("$") == -1)
                    {
                        DataTable table = Parse(cnn, SheetName, false);

                        if (table.Rows.Count != 0)
                        {
                            ds.Tables.Add(table);
                        }
                    }
                }
            }
            finally
            {
                cnn.Close();
            }
            return(ds);
        }