string execelConnectionStr = "Provider=Microsoft.Jet.Oledb.4.0;data source=" + path + @";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
这段代码只能导入不带密码的excel,加了密码不行了,加了User ID=Admin;password=; 这样还是不行?快疯了,大家帮帮忙,谢谢了! 在这里发了第四份贴了,郁闷
这段代码只能导入不带密码的excel,加了密码不行了,加了User ID=Admin;password=; 这样还是不行?快疯了,大家帮帮忙,谢谢了! 在这里发了第四份贴了,郁闷
解决方案 »
- C#打包问题
- 一个关于Button的问题
- C#怎样实现dateTimePicker当点击年份,月份,日,的时候显示不同的对话框。
- 最后一百分了!请大家帮帮我看看。
- C# 向VC++发送消息
- div+CSS怎么布局左中右的框架
- 求助,我用VC写了一个Dll,用C#生成的成在本机可以,在其他机器却无法加载这个dll
- 如何把两个数值变量的值相除保留2位小数
- 关于改变控件边框的颜色??
- MS VS.NET出了RC1,BORLAND KYLIX 出了VERSION 2 。
- 我想把带密码的word和excel的密码取消了(知道密码)
- WPF中使用ADO.NET Entity Data Model操作数据库添加不上数据
同数据库连接一样的把userid和密码写进去就可以了
string execelConnectionStr = "Provider=Microsoft.Jet.Oledb.4.0;data source=" + path + @";User ID=admin;password=ab;Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
然后导入这个解密的文件
删除另存的文件就好了
反正用户看不见你后台怎么操作的
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Runtime.InteropServices;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{ Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); xlApp.DisplayAlerts = false; //789就是密码
xlApp.Workbooks.Open("D:\\123.xlsx", Missing.Value, Missing.Value, Missing.Value, "789", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Workbook xlBook = xlApp.Workbooks[1];
if (xlBook.HasPassword)
{
xlBook.Unprotect(Missing.Value);
}
//第三个参数是密码 直接给个null 就是没有密码
xlBook.SaveAs("D:\\没有密码.xlsx", Missing.Value,null, Missing.Value, Missing.Value, Missing.Value, XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); xlApp.ActiveWorkbook.Close(false, Type.Missing, Type.Missing); xlApp.Quit(); IntPtr t = new IntPtr(xlApp.Hwnd);
int k = 0;
GetWindowThreadProcessId(t, out k);
System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);
p.Kill();
} [DllImport("User32.dll", CharSet = CharSet.Auto)]
private static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);
}
}