Skip to content

OLEDB External table is not in the expected format. #759

Closed

Description

@shps951023

Image

Activity

  1. added
    bug
    on Apr 12, 2025
  2. self-assigned this
    on Apr 12, 2025
  3. michelebastione commented on Apr 13, 2025

    @michelebastione
    Collaborator

    @shps951023 I've tried the following and it worked without any problems:

    var path = PathHelper.GetFile("xlsx/TestTypeMapping.xlsx");
    var connString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={path};Extended Properties=\"Excel 12.0;HDR=YES\"";
    using var conn = new OleDbConnection(connString);
    conn.Open();
            
    var schema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
    var sheet = schema.Rows[0]["TABLE_NAME"].ToString();
            
    using var cmd = conn.CreateCommand();
    cmd.CommandText = $"SELECT * FROM [{sheet}]";
            
    using var reader = cmd.ExecuteReader();
    MiniExcel.SaveAs(@"c:\users\computer\desktop\tmp.xlsx", reader);

    Maybe there's something irregular in your excel file?

  4. shps951023 commented on Apr 14, 2025

    @shps951023
    MemberAuthor

    @michelebastione this issue from China's gitee https://gitee.com/dotnetchina/MiniExcel/issues/I53AVX (there're 221 issues 😅)

    Issue code :
    demo.zip

  5. shps951023 commented on Apr 14, 2025

    @shps951023
    MemberAuthor
    using MiniExcelLibs;
    using System.Data;
    using System.Data.OleDb;
    
    class Program
    {
        static void Main()
        {
            var path = Path.GetTempPath() + Guid.NewGuid() + ".xlsx";
            var list = Enumerable.Range(0, 1000).Select(s => new { val = Guid.NewGuid(), val2 = Guid.NewGuid() });
            MiniExcel.SaveAs(path, list);
            Console.WriteLine(path);
    
            string connectionString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={path};Extended Properties=\"Excel 12.0 Xml;HDR=YES\";";
    
            try
            {
                using (OleDbConnection conn = new OleDbConnection(connectionString))
                {
                    conn.Open();
    
                    var schema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                    var sheet = schema.Rows[0]["TABLE_NAME"].ToString();
    
                    using var cmd = conn.CreateCommand();
                    cmd.CommandText = $"SELECT * FROM [{sheet}]";
    
                    using (var reader = cmd.ExecuteReader())
                    {
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            Console.Write($"{reader.GetName(i)}  ");
                        }
                        Console.WriteLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error:{ex.Message}");
            }
        }
    }
  6. michelebastione commented on Apr 14, 2025

    @michelebastione
    Collaborator

    Mmh ok I understand. I assume this is due to the fact that the generated xml even though it follows the openxml specifications is not quite "microsoft compliant".

  7. deleted a comment from on Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions