永发信息网

domino中excel的导入导出如何实现?

答案:2  悬赏:60  手机版
解决时间 2021-01-31 11:47
domino中excel的导入导出如何实现?
最佳答案
运行这段代码的时候,必须保证Excel的数据格式与文档的数据格式一致,一个单元格对应一个域。
本代码从第二行开始读取,认为第一行是标题,而不是有用的数据。
本代码判断Excel数据已经读取完毕的条件是:准备读取的第一个单元格的内容为空。
导入后,刷新视图就可以显示数据了。

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace 'workspace
Dim ss As New NotesSession 'session
Dim db As NotesDatabase 'database
Dim files As Variant 'file name
Dim schar As String 'cell content
Dim doc As NotesDocument 'notes document
Dim excelapplication
Dim i,sheet
Set db = ss.currentdatabase
files = ws.openfiledialog(False,"请选择要导入的Excel文件","Excel file/*.xls")
sheeet = 1
If Not(Isempty(files)) Then '如果用户选择了文件,或者输入了文件名,那么就开始准备打开excel文件。
Set excelapplication = createobject("excel.application")
Set excelworkbook = excelapplication.workbooks.open(files)

If excelworkbook Is Nothing Then '如果未找到文件,则退出
excelapplication.quit
Exit Sub
End If
Set excelsheet = excelworkbook.worksheets(1)
i = 2 '从第二行开始读取
'一个sheet里面所有记录循环
Do Until Cstr(excelsheet.cells(i,1).value) =""
Set doc = New NotesDocument(db)
doc.Form = "物资计划"
doc.xmmc = excelsheet.cells(i,1).value '项目名称
doc.jhbh = excelsheet.cells(i,2).value '计划编号
doc.jhfypc = excelsheet.cells(i,3).value '计划发运批次
doc.clmc = excelsheet.cells(i,4).value '材料名称
doc.ggxh = excelsheet.cells(i,5).value '规格型号
doc.bz = excelsheet.cells(i,6).value '备注
doc.cz = excelsheet.cells(i,7).value '材质
doc.dw = excelsheet.cells(i,8).value '单位
doc.jhsl = excelsheet.cells(i,9).value '计划数量
doc.dhsjyq = excelsheet.cells(i,10).value '到货时间要求
doc.shyj = excelsheet.cells(i,11).value '审核意见
doc.cgr = excelsheet.cells(i,12).value '采购人
doc.ht_loadmark="Excel 导入 at " + Cstr(Now())
Call doc.save(False,False) '保存
i=i+1
Loop
excelworkbook.close(False)
excelapplication.quit
Set excelapplication = Nothing
End If
End Sub
------------------------------------------------------------------------

应当注意的是:如果当前视图一个文档也没有显式的选中(即用鼠标点取),那么lotus会自动默认选中第一条文档。
Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim curdoc As NotesDocument
Set uidoc = ws.CurrentDocument
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim session As New NotesSession
Dim excelApplication As Variant
Dim excelWorkbook As Variant
Dim excelSheet As Variant
Dim collection As notesdocumentcollection
Dim i,index1,index2 As Integer
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments 'UnprocessedDocuments是选中的文档集合
Set doc = collection.GetFirstDocument()
If (doc Is Nothing) Then
Messagebox("请选择你要导出的记录!")
Exit Sub
End If
filenames = ws.SaveFileDialog(False,"导出到Excel","Excel文件|*.xls", "C:", "物资计划按项目.xls")

If Isempty(filenames) Then '如果没有得到文件名,则提示后退出
Messagebox("未提供目标文件名称")
Exit Sub
End If

Set excelApplication = CreateObject("Excel.Application") '创建Excel对象
excelApplication.Visible = True '显示Excel
Set excelWorkbook = excelApplication.Workbooks.Add '添加表
Set excelSheet = excelWorkbook.Worksheets("Sheet1") '选中表
'第1行写标题
excelSheet.Cells(1,1).Value = "项目名称"
excelSheet.Cells(1,2).Value = "计划编号"
excelSheet.Cells(1,3).Value = "计划发运批次"
excelSheet.Cells(1,4).Value = "材料名称"
excelSheet.Cells(1,5).Value = "规格型号"
excelSheet.Cells(1,6).Value = "材质"
excelSheet.Cells(1,7).Value = "单位"
excelSheet.Cells(1,8).Value = "计划数量"
excelSheet.Cells(1,9).Value = "到货时间要求"
excelSheet.Cells(1,10).Value = "审核意见"
'从第2行开始写数据
i = 2
While Not(doc Is Nothing)
excelSheet.Cells(i,1).Value = doc.xmmc(0)
excelSheet.Cells(i,2).Value = doc.jhbh(0)
excelSheet.Cells(i,3).Value = doc.jhfypc(0)
excelSheet.Cells(i,4).Value = doc.clmc(0)
excelSheet.Cells(i,5).Value = doc.ggxh(0)
excelSheet.Cells(i,6).Value = doc.cz(0)
excelSheet.Cells(i,7).Value = doc.dw(0)
excelSheet.Cells(i,8).Value = doc.jhsl(0)
excelSheet.Cells(i,9).Value = doc.dhsjyq(0)
excelSheet.Cells(i,10).Value =doc.shyj(0)
i = i+1
Set doc = collection.GetNextDocument(doc)
Wend
excelWorkbook.SaveAs(filenames(0))
excelApplication.Quit
Set excelApplication = Nothing
Messagebox("文件已保存到" +filenames(0))
End Sub
全部回答
搜一下:domino中excel的导入导出如何实现?
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
请问 925 银是纯银吗。?只说是还是不是`谢谢
滁州市出入境检验检疫局
鲍参堂地址好找么,我有些事要过去
男生对女生特别关心 处处为女生着想 说明什么
等弧的长度相等 等弧所对的圆心角度数相等 这
怀仁县高考二模成绩重点怀仁六中
武则天曾服侍唐朝过几代皇帝?
北域珍品特产店地址在什么地方,想过去办事
参盛岛海参地址有知道的么?有点事想过去
本好长海海参地址有知道的么?有点事想过去
单位要小额贷款让员工签字我该怎么办10分
解梦肉丢了 梦见把自己的一大快肉分给别人一
南开老校区都有什么学院
日历上星期一到星期日,分别用什么字母代表
一段话的日记十个
推荐资讯
结婚登记照能穿黑色衣服吗
您好,请问“九阳合千润专卖店”是九阳官方授
修炼之门入场券的问题
灯罩可使灯泡射向上方的光向着下方照,这是应
我想要卓尔英语高三听力录音,能给我一份吗,
惴字怎么读
MyFace地址在什么地方,想过去办事
泪袋扩眼人鱼能使单眼皮成为双眼皮么
大神们,做蛋黄酥的油皮揉面必须得揉到扩展阶
上高中了,不爱学习怎么办?
电影狼牙里面那个有高又猛的那个人叫什么
双峰县人民检察院反渎职侵权局地址在什么地方
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?