在c#中打开密码保护的Excel [英] Open password protected excel in c#

查看:339
本文介绍了在c#中打开密码保护的Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我一直在网上搜索如何在不使用互操作类的情况下打开excel 2007密码保护文件的解决方案。



我更喜欢开源库。我试过EPPlus但是我得到了错误(内存异常和值不能为空异常)。



所以主要的问题是,如何在没有内容的情况下打开Excel文件使用互操作,如果他们受密码保护,我如何打开它们,我有密码详细信息?

解决方案

试试这个希望它有所帮助。



ExcelCrackerCS [ ^ ]



< a href =http://www.connectionstrings.com/excel> excel的连接线 [ ^ ]



来自StackOverFlow:



http://stackoverflow.com/a/13806242 [ ^ ]





  private   string  ExcelConnection( string  fileName)
{
return
@ <跨度class =code-string> Provider = Microsoft.Jet.OLEDB.4.0; +
@ 数据源= + fileName + ; +
@ 扩展属性= + Convert.ToChar( 34 )。ToString()+
@ Excel 8.0 +转换.ToChar( 34 )。ToString()+ ; ;
}

private DataTable readExcel( string fileName, string sql)
{
OleDbConnection conn = new OleDbConnection(ExcelConnection(fileName));
OleDbCommand cmd = new OleDbCommand(sql,conn);
OleDbDataAdapter adp = new OleDbDataAdapter();
adp.SelectCommand = cmd;
DataTable dt = new DataTable();

尝试
{
adp.FillSchema(dt,SchemaType.Source);
adp.Fill(dt);
}
catch
{

}
返回 dt;
}





尝试这个答案如何使用C#在asp.net中读取受密码保护的excel文件 [ ^ ]


  private  < span class =code-keyword> string  ExcelConnection( string  fileName)
{
return
@ Provider = Microsoft.Jet.OLEDB.4.0; +
@ 数据源= + fileName + ; +
@ 扩展属性= + Convert.ToChar( 34 )。ToString()+
@ Excel 8.0 + Convert.ToChar( 34 )。ToString()+ ;;
}

private DataTable readExcel( string fileName, string sql)
{
OleDbConnection conn = new OleDbConnection(ExcelConnection(fileName));
OleDbCommand cmd = new OleDbCommand(sql,conn);
OleDbDataAdapter adp = new OleDbDataAdapter();
adp.SelectCommand = cmd;
DataTable dt = new DataTable();

尝试
{
adp.FillSchema(dt,SchemaType.Source);
adp.Fill(dt);
}
catch
{

}
返回 dt;
}


亲爱的使用EPPlus库..........

Hi,

I have been searching the net for solutions on how to to open excel 2007 password protected files without using the interop classes.

I would prefer open source libraries. I tried EPPlus but im getting errors(out of memory exceptions and value can not be null exception).

SO the main question is, how can I open Excel files without using interop and how do i go about opening them if they are password protected and I have the password details?

解决方案

Try this hope it helps.

ExcelCrackerCS[^]

connectionstrings of excel[^]

From StackOverFlow:


http://stackoverflow.com/a/13806242[^]



private string ExcelConnection(string fileName)
    {
        return
            @"Provider=Microsoft.Jet.OLEDB.4.0;" +
            @"Data Source=" + fileName + ";" +
            @"Extended Properties=" + Convert.ToChar(34).ToString() +
            @"Excel 8.0" + Convert.ToChar(34).ToString() + ";";
    }

    private DataTable readExcel(string fileName, string sql)
    {
        OleDbConnection conn = new OleDbConnection(ExcelConnection(fileName));
        OleDbCommand cmd = new OleDbCommand(sql, conn);
        OleDbDataAdapter adp = new OleDbDataAdapter();
        adp.SelectCommand = cmd;
        DataTable dt = new DataTable();

        try
        {
            adp.FillSchema(dt, SchemaType.Source);
            adp.Fill(dt);
        }
        catch
        { 

        }
        return dt;
    }



Try this answer too How to read Password protected excel file in asp.net with C#[^]


private string ExcelConnection(string fileName)
    {
        return
            @"Provider=Microsoft.Jet.OLEDB.4.0;" +
            @"Data Source=" + fileName + ";" +
            @"Extended Properties=" + Convert.ToChar(34).ToString() +
            @"Excel 8.0" + Convert.ToChar(34).ToString() + ";";
    }

    private DataTable readExcel(string fileName, string sql)
    {
        OleDbConnection conn = new OleDbConnection(ExcelConnection(fileName));
        OleDbCommand cmd = new OleDbCommand(sql, conn);
        OleDbDataAdapter adp = new OleDbDataAdapter();
        adp.SelectCommand = cmd;
        DataTable dt = new DataTable();

        try
        {
            adp.FillSchema(dt, SchemaType.Source);
            adp.Fill(dt);
        }
        catch
        { 

        }
        return dt;
    }


Dear Use EPPlus Library..........


这篇关于在c#中打开密码保护的Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆