以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请教导出  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=92380)

--  作者:hbhb
--  发布时间:2016/11/2 11:51:00
--  请教导出
大师:见实例,为何导出时输入新的文件名导出没有问题。如果再导出,然后选择同样的文件名替换它,为何就不行了?
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目21.zip


--  作者:有点色
--  发布时间:2016/11/2 12:25:00
--  

Dim bt As String = "导出表"
Dim tbtable As Table = e.Form.Controls("Table1").Table


Dim flg As New SaveExcelFlags
flg.CellStyle = False
Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    tbtable.SaveExcel(dlg.FileName,bt,flg)  \'保存文件
Else
   
    Return
End If


Dim App As New MSExcel.Application
try
    app.DisplayAlerts = False
    Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName)
    Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(bt)
    MessageBox.Show(1)
    Dim Rg2 As MSExcel.Range = Ws.Range("A1")  \'以这个指定的单元格为基准
    MessageBox.Show(2)
    Ws.Unprotect(Password:="foxtable")
    Rg2.EntireRow.Insert(MSExcel.XlInsertShiftDirection.xlShiftDown)\'在基准单元格上面插入一行
    MessageBox.Show(3)
    Dim rgx As MSExcel.Range = ws.Range("A1")
    rgx.value = bt
    rgx.RowHeight = 25
    With Ws.Range("A1").Font
        .Name = "黑体" \'字体
        .Size = 12 \'字号
        \'.Bold = True   \'加粗
        \'.Italic = True \'斜体
        \'.ColorIndex = 3\'颜色
    End With
   
    rgx.HorizontalAlignment = MSExcel.Constants.xlCenter \'水平居中
    Dim Rg1 As MSExcel.Range = Ws.UsedRange
    Dim hs As Integer
    Dim ls As Integer
    hs = Rg1.Rows.Count
    ls = Rg1.Columns.Count
    Dim Rg3 As MSExcel.Range = Ws.Range(Ws.Cells(1,1),Ws.Cells(1,ls))
    App.DisplayAlerts = False \'加上此行可禁止弹出合并前的提示
    Rg3.Merge  \'合并指定区域的单元格
    Dim rg As MSExcel.Range
    rg = Ws.Range(Ws.Cells(2,1),Ws.Cells(hs,ls))
    With Rg.Borders(MSExcel.XlBordersIndex.xlInsideHorizontal)   \'---设置表格内部横线
        .LineStyle = MSExcel.XlLineStyle.xlDot
        .Weight = MSExcel.XlBorderWeight.xlHairline
        .ColorIndex = 1
    End With
    With Rg.Borders(MSExcel.XlBordersIndex.xlInsideVertical)   \'---设置表格内部竖线
        .LineStyle = MSExcel.XlLineStyle.xlDot
        .Weight = MSExcel.XlBorderWeight.xlHairline
        .ColorIndex = 1
    End With
   
   
    With Rg.Borders(MSExcel.XlBordersIndex.xlEdgeTop)   \'----表格上边线
        .LineStyle = MSExcel.XlLineStyle.xlDouble
        .Weight = MSExcel.XlBorderWeight.xlThick
        .ColorIndex = 1
    End With
   
    With Rg.Borders(MSExcel.XlBordersIndex.xlEdgeBottom)  \'--表格下边线--
        .LineStyle = MSExcel.XlLineStyle.xlDouble
        .Weight = MSExcel.XlBorderWeight.xlThick
        .ColorIndex = 1
    End With
   
    With Rg.Borders(MSExcel.XlBordersIndex.xlEdgeLeft)   \'---表格左边线
        .LineStyle = MSExcel.XlLineStyle.xlContinuous
        .Weight = MSExcel.XlBorderWeight.xlThin
        .ColorIndex = 1
    End With
    With Rg.Borders(MSExcel.XlBordersIndex.xlEdgeRight)  \'---表格右边线
        .LineStyle = MSExcel.XlLineStyle.xlContinuous
        .Weight = MSExcel.XlBorderWeight.xlThin
        .ColorIndex = 1
    End With
   
    \'-----保护单元格---
    Dim Rg5 As MSExcel.Range = Ws.Range(ws.cells(1,1),ws.cells(1,tbtable.Cols.Count))\'指定任意单元格区域
    Ws.Unprotect(Password:="foxtable")\'撤销对工作表的保护
    Ws.Cells.Locked = False \'解除整个工作表所有单元格的锁定
    Rg5.Locked = True\'锁定指定的单元格
    Ws.Protect(Password:="foxtable", AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True)
    Wb.Save
    App.quit
   
   
    MessageBox.Show("导出完毕!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
   
catch ex As exception
    msgbox(ex.message)
    app.quit
End try


--  作者:hbhb
--  发布时间:2016/11/2 12:39:00
--  
谢谢!自己摸索半天,不如请教一遍。导师就是不一样?
--  作者:有点蓝
--  发布时间:2016/11/2 14:30:00
--  
就因为你缺少自己的摸索经验,所以缺乏判断问题原因的能力。依赖习惯了,就像笼中鸟一样,离不开笼子
--  作者:hbhb
--  发布时间:2016/11/2 14:43:00
--  
我是拿来主义者,业余的业余主义者,崇拜主义者,拜神主义者。摸索石头过河,不如自游泳过河。我不会游泳怎办呀?
--  作者:hbhb
--  发布时间:2016/11/2 14:55:00
--  
一看帮助要睡觉,香烟抽了无数包,提神醒脑也无效,一看电视就来劲,可惜只有一个脑。敢问谁有特效药,笑看帮助感谢了!