Dim oOWC As OWC10.SpreadsheetClass
oOWC = new OWC10.SpreadsheetClass
oOWC.XMLURL = MapPath("abc.xls")
总是运行到这一步就抛出异常, 我试过OWC的其他方法属性,好象没有问题,就XMLURL不行。
异常详细信息: System.Runtime.InteropServices.COMException: HRESULT 中的异常:0xE0040104。
看了别人例子的代码都是这样写的, 是不是应该还有一些什么环境我没有设置? OWC10.SpreadsheetClass类型已经认出来,说明已经成功添加了引用.
这个问题上次在CSDN上问了一个星期都没有人会~~~
4 个解决方案
#1
发错地方了吧,请发到asp.net里去啊
#2
CSDN无高手啊~~~
自己顶。
自己顶。
#3
我用的是FarPoint.Web.Spread.FpSpread!不知和你的OWC SpreadSheet 是一个控件吗?
#4
先将xls另存为xml文件.然后使用xmlurl或xmldata 这二天也用这个.
Dim ofd As New OpenFileDialog
ofd.DefaultExt = "xls"
ofd.Filter = "Excel文件 (*.xls)|*.xls"
If ofd.ShowDialog = DialogResult.Cancel Then
Exit Sub
Else
Dim strname As String = ofd.FileName
If strname <> "" Then
strExportName = Now.ToString("yyyyMMddHHmmss").ToString & ".xml"
strExportName = Functions.Path & "\" & strExportName
Dim MisValueExcel As Object = System.Reflection.Missing.Value
Dim xlFileType As Object = Excel.XlFileFormat.xlXMLSpreadsheet
Dim ex As New Excel.Application
ex.Visible = False
ex.DisplayAlerts = False
Dim books As Excel.Workbooks
books = ex.Workbooks
books.Open(strname)
Dim book As Excel.Workbook = books.Item(1)
book.SaveAs(strExportName, xlFileType, MisValueExcel, MisValueExcel, MisValueExcel, MisValueExcel, Excel.XlSaveAsAccessMode.xlNoChange, , MisValueExcel, MisValueExcel, MisValueExcel, MisValueExcel)
book.Close(False)
NAR(book)
NAR(books)
ex.Quit()
NAR(ex)
Me.AxSpreadsheet1.XMLURL = strExportName
With Me.AxSpreadsheet1.ActiveSheet.Rows(1).Font
.ColorIndex = 3
.Bold = True
End With
End If
End If
End Sub
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
看看吧,希望对你有用.
Dim ofd As New OpenFileDialog
ofd.DefaultExt = "xls"
ofd.Filter = "Excel文件 (*.xls)|*.xls"
If ofd.ShowDialog = DialogResult.Cancel Then
Exit Sub
Else
Dim strname As String = ofd.FileName
If strname <> "" Then
strExportName = Now.ToString("yyyyMMddHHmmss").ToString & ".xml"
strExportName = Functions.Path & "\" & strExportName
Dim MisValueExcel As Object = System.Reflection.Missing.Value
Dim xlFileType As Object = Excel.XlFileFormat.xlXMLSpreadsheet
Dim ex As New Excel.Application
ex.Visible = False
ex.DisplayAlerts = False
Dim books As Excel.Workbooks
books = ex.Workbooks
books.Open(strname)
Dim book As Excel.Workbook = books.Item(1)
book.SaveAs(strExportName, xlFileType, MisValueExcel, MisValueExcel, MisValueExcel, MisValueExcel, Excel.XlSaveAsAccessMode.xlNoChange, , MisValueExcel, MisValueExcel, MisValueExcel, MisValueExcel)
book.Close(False)
NAR(book)
NAR(books)
ex.Quit()
NAR(ex)
Me.AxSpreadsheet1.XMLURL = strExportName
With Me.AxSpreadsheet1.ActiveSheet.Rows(1).Font
.ColorIndex = 3
.Bold = True
End With
End If
End If
End Sub
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
看看吧,希望对你有用.
#1
发错地方了吧,请发到asp.net里去啊
#2
CSDN无高手啊~~~
自己顶。
自己顶。
#3
我用的是FarPoint.Web.Spread.FpSpread!不知和你的OWC SpreadSheet 是一个控件吗?
#4
先将xls另存为xml文件.然后使用xmlurl或xmldata 这二天也用这个.
Dim ofd As New OpenFileDialog
ofd.DefaultExt = "xls"
ofd.Filter = "Excel文件 (*.xls)|*.xls"
If ofd.ShowDialog = DialogResult.Cancel Then
Exit Sub
Else
Dim strname As String = ofd.FileName
If strname <> "" Then
strExportName = Now.ToString("yyyyMMddHHmmss").ToString & ".xml"
strExportName = Functions.Path & "\" & strExportName
Dim MisValueExcel As Object = System.Reflection.Missing.Value
Dim xlFileType As Object = Excel.XlFileFormat.xlXMLSpreadsheet
Dim ex As New Excel.Application
ex.Visible = False
ex.DisplayAlerts = False
Dim books As Excel.Workbooks
books = ex.Workbooks
books.Open(strname)
Dim book As Excel.Workbook = books.Item(1)
book.SaveAs(strExportName, xlFileType, MisValueExcel, MisValueExcel, MisValueExcel, MisValueExcel, Excel.XlSaveAsAccessMode.xlNoChange, , MisValueExcel, MisValueExcel, MisValueExcel, MisValueExcel)
book.Close(False)
NAR(book)
NAR(books)
ex.Quit()
NAR(ex)
Me.AxSpreadsheet1.XMLURL = strExportName
With Me.AxSpreadsheet1.ActiveSheet.Rows(1).Font
.ColorIndex = 3
.Bold = True
End With
End If
End If
End Sub
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
看看吧,希望对你有用.
Dim ofd As New OpenFileDialog
ofd.DefaultExt = "xls"
ofd.Filter = "Excel文件 (*.xls)|*.xls"
If ofd.ShowDialog = DialogResult.Cancel Then
Exit Sub
Else
Dim strname As String = ofd.FileName
If strname <> "" Then
strExportName = Now.ToString("yyyyMMddHHmmss").ToString & ".xml"
strExportName = Functions.Path & "\" & strExportName
Dim MisValueExcel As Object = System.Reflection.Missing.Value
Dim xlFileType As Object = Excel.XlFileFormat.xlXMLSpreadsheet
Dim ex As New Excel.Application
ex.Visible = False
ex.DisplayAlerts = False
Dim books As Excel.Workbooks
books = ex.Workbooks
books.Open(strname)
Dim book As Excel.Workbook = books.Item(1)
book.SaveAs(strExportName, xlFileType, MisValueExcel, MisValueExcel, MisValueExcel, MisValueExcel, Excel.XlSaveAsAccessMode.xlNoChange, , MisValueExcel, MisValueExcel, MisValueExcel, MisValueExcel)
book.Close(False)
NAR(book)
NAR(books)
ex.Quit()
NAR(ex)
Me.AxSpreadsheet1.XMLURL = strExportName
With Me.AxSpreadsheet1.ActiveSheet.Rows(1).Font
.ColorIndex = 3
.Bold = True
End With
End If
End If
End Sub
Private Sub NAR(ByVal o As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
看看吧,希望对你有用.