-- 作者:cnsjroom
-- 发布时间:2022/9/29 9:57:00
-- Merge()操作时 出现 不可识别的数据库格式 提示
Merge()操作时 出现 不可识别的数据库格式 提示
\'\'\' 保存数据 Public Sub form527_excel1_Ajax(rq as Request) Dim dt As Table = Tables("文书名表名窗体id对应表") Dim nms() As String = {"措施类别","文书名","文书简称","对应表名","窗体id","文书条款"} \'要导出的列名 Dim caps() As String = {"措施类别","文书名","文书简称","对应表名","窗体id","文书条款"} \'对应的列标题 Dim szs() As Integer = {100,200,80,200,80,820} \'对应的列宽 Dim Book As New XLS.Book \'定义一个Excel工作簿 Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表 Dim st As XLS.Style = Book.NewStyle \'日期列的显示格式 st.Format = "yyyy-MM-dd" For c As Integer = 0 To nms.length -1 Sheet(0, c).Value = caps(c) \'指定列标题 Sheet.Cols(c).Width = szs(c) \'指定列宽 If dt.Cols(nms(c)).IsDate Then \'如果是日期列 Sheet.Cols(c).Style = st \'设置显示格式 End If Next For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据 For c As Integer = 0 To nms.length -1 Sheet(r +1, c).Value = dt.rows(r)(nms(c)) Next Next Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog dlg.Filter= "Excel文件|*.xls" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then Book.Save(dlg.FileName) Dim Proc As New Process Proc.File = dlg.FileName Proc.Start() End If End Sub
\'\'\' 保存数据 Public Sub form527_excel2_Ajax(rq as Request) Dim dlg As New OpenFileDialog dlg.Filter = "excel文件|*.xls" dlg.MultiSelect = True \'允许选择多个文件 If dlg.ShowDialog =DialogResult.OK Then For Each fl As String In dlg.FileNames Dim mg As New Merger mg.SourcePath = fl mg.Fields= "措施类别,文书名,文书简称,对应表名,窗体id,文书条款" mg.SourceTableName = "sheet1$" mg.DataTableName = "文书名表名窗体id对应表" mg.Merge() Next End If End Sub
错误的事件名称 System.Data.OleDb.OleDbException (0x80004005): 不可识别的数据库格式 \'C:\\Users\\Administrator\\Desktop\\321.xls\'。 在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) 在 System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) 在 System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) 在 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) 在 System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) 在 System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) 在 Foxtable.Merger.Merge() 2022-09-29 09:54:58
|
-- 作者:cnsjroom
-- 发布时间:2022/9/29 11:56:00
-- 回复:(有点蓝)导入前,文件不能处于打开状态
老师 在沿用这个代码的前提下,怎么增加一个条件 类型=\'1\' 的才能导出呢?
Dim dt As Table = Tables("文书名表名窗体id对应表") Dim nms() As String = {"措施类别","文书名","文书简称","对应表名","窗体id","文书条款"} \'要导出的列名 Dim caps() As String = {"措施类别","文书名","文书简称","对应表名","窗体id","文书条款"} \'对应的列标题 Dim szs() As Integer = {100,200,80,200,80,820} \'对应的列宽 Dim Book As New XLS.Book \'定义一个Excel工作簿 Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表 Dim st As XLS.Style = Book.NewStyle \'日期列的显示格式 st.Format = "yyyy-MM-dd" For c As Integer = 0 To nms.length -1 Sheet(0, c).Value = caps(c) \'指定列标题 Sheet.Cols(c).Width = szs(c) \'指定列宽 If dt.Cols(nms(c)).IsDate Then \'如果是日期列 Sheet.Cols(c).Style = st \'设置显示格式 End If Next For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据 For c As Integer = 0 To nms.length -1 Sheet(r +1, c).Value = dt.rows(r)(nms(c)) Next Next Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog dlg.Filter= "Excel文件|*.xls" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then Book.Save(dlg.FileName) Dim Proc As New Process Proc.File = dlg.FileName Proc.Start() End If
|