c# 为excel单元格添加链接时,总是出现异常来自 HRESULT:0x800A03EC 10
//代码如下:总是在sheet1.Hyperlinks.Add(range,"http://www.abc123.com",Missing.Value,Missing.V...
//代码如下:总是在sheet1.Hyperlinks.Add(range, "http://www.abc123.com", Missing.Value, Missing.Value, Missing.Value);这句出现异常来自 HRESULT:0x800A03EC,寻遍google和百度,什么改变语言选项,先保存再来设等各种方法,无一有用,有知道的朋友请不吝赐教,谢谢!!!
Control.CheckForIllegalCrossThreadCalls = false;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "打开(Open)";
ofd.FileName = "";
ofd.InitialDirectory = exePath;
ofd.InitialDirectory = System.Windows.Forms.Application.StartupPath;
ofd.Filter = "Excel文件|*.xls";
ofd.ValidateNames = true;
ofd.CheckFileExists = true;
ofd.CheckPathExists = true;
try
{
if (ofd.ShowDialog() == DialogResult.OK)
{
Microsoft.Office.Interop.Excel.ApplicationClass myExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
Workbook wb = myExcel.Workbooks.Open(ofd.FileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Worksheet sheet1 = (Worksheet)wb.Sheets[1];
Range range = sheet1.get_Range("a1", "a1");
//下面这行代码总是报{"异常来自 HRESULT:0x800A03EC"}
sheet1.Hyperlinks.Add(range, "http://www.abc123.com", Missing.Value, Missing.Value, Missing.Value);
wb.Save();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
} 展开
Control.CheckForIllegalCrossThreadCalls = false;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "打开(Open)";
ofd.FileName = "";
ofd.InitialDirectory = exePath;
ofd.InitialDirectory = System.Windows.Forms.Application.StartupPath;
ofd.Filter = "Excel文件|*.xls";
ofd.ValidateNames = true;
ofd.CheckFileExists = true;
ofd.CheckPathExists = true;
try
{
if (ofd.ShowDialog() == DialogResult.OK)
{
Microsoft.Office.Interop.Excel.ApplicationClass myExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
Workbook wb = myExcel.Workbooks.Open(ofd.FileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Worksheet sheet1 = (Worksheet)wb.Sheets[1];
Range range = sheet1.get_Range("a1", "a1");
//下面这行代码总是报{"异常来自 HRESULT:0x800A03EC"}
sheet1.Hyperlinks.Add(range, "http://www.abc123.com", Missing.Value, Missing.Value, Missing.Value);
wb.Save();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询