导入:CS版本
Dim ws As New notesuiworkspace
Dim ss As New notessession
Dim db As notesdatabase
Dim view As NotesView
Dim doc As NotesDocument
Set db = ss.CurrentDatabase
Dim i,sum_all,sum_success As Integer
Dim keyindex As String
Dim errorinfo As String
Set view=db.GetView("(viewforupdate)")
files = ws.openfiledialog(False,"请选择数据源","Excel file/*.xls","D:")
If files(0) = "" Then
Exit Sub
End If
Set excelapplication = createobject("excel.application")
Set excelworkbook = excelapplication.workbooks.open(files)
Set excelsheet = excelworkbook.worksheets(1)
i = 2
sum_all = 0
sum_success = 0
keyindex = Lcase$(Trim(Cstr(excelsheet.cells(i,1).value)))
Do Until keyindex = ""
Set doc = view.GetDocumentbykey(keyindex)
If Not (doc Is Nothing) Then
doc.Manager = excelsheet.cells(i,3).value
doc.ManagerID = Lcase$(Trim(excelsheet.cells(i,2).value))
doc.ManagerID_view = Lcase$(Trim(excelsheet.cells(i,2).value))
doc.Manager1 = excelsheet.cells(i,5).value
doc.ManagerID1 = Lcase$(Trim(excelsheet.cells(i,4).value))
doc.ManagerID_view1 = Lcase$(Trim(excelsheet.cells(i,4).value))
i = i+1
sum_success = sum_success + 1
sum_all = sum_all + 1
Call doc.save(False,False)
Else
i = i+1
sum_all = sum_all + 1
errorinfo = errorinfo + " -- " + keyindex
End If
keyindex = Lcase$(Trim(Cstr(excelsheet.cells(i,1).value)))
Loop
excelworkbook.close(False)
excelapplication.quit
Set excelapplication = Nothing
Messagebox "确认:共 "+Cstr(sum_all)+" 条记录,成功更新 "+Cstr(sum_success)+"条!"+"\r\n" + "错误的帐号为:"+errorinfo
BS版本的
Dim ss As New NotesSession
Dim db As NotesDatabase
Dim dcctemp As NotesDocumentCollection
Dim doc As NotesDocument
Dim docTemp As NotesDocument
Dim vw As NotesView
Set db = ss.CurrentDatabase
Set doc = ss.DocumentContext
Set vw = db.GetView("Search_StudentByClassStage_View")
If vw Is Nothing Then
Exit Sub
End If
'获得本期第一个学员信息(通过有多少门课,确定应该多少列)
Set dccTemp = vw.GetAllDocumentsByKey(doc.BNType(0) + "#" + doc.ClassStage(0),True)
Set docTemp = dccTemp.GetFirstDocument
If docTemp Is Nothing Then
Print |<script>alert("无对应日期的数据")</script>|
Print |<script>history.back()</script>|
Exit Sub
End If
'初始化Excel组件
Print |<script lanuage="javascript">|
Print |var varExcelApplication = new ActiveXObject("Excel.Application");|
Print |var varWorkbook = varExcelApplication.Workbooks.Add();|
Print |var varWorkSheet = varWorkbook.Worksheets(1)|
Print |varWorkSheet.Name = "sheet1"|
Print |varWorkSheet.Rows("1:1").Select()|
Print |var varSelection = varExcelApplication.Selection|
Print |varSelection.Font.Name = "宋体"|
Print |varSelection.Font.Size = 10|
Print |varSelection.Font.Bold = true|
Print |varSelection.HorizontalAlignment = -4108|
Print |varWorkSheet.Columns("A:Z").Select|
Print |var varSelection = varExcelApplication.Selection|
Print |varSelection.NumberFormatLocal = "@"|
'打印表头start-----------------
strColName = "序号;工号"
For i = 1 To 30
strNum = Cstr(i)
If docTemp.HasItem("Course_"+strNum) Then
strColName = strColName + ";课程" + strNum + ";分数" + strNum + ";评语" + strNum
End If
Next
varColName = Split(strColName,";")
For i = 0 To Ubound(varColName)
Print |varWorkSheet.Range("| + Chr(65 + i) + |1").FormulaR1C1 = "| + varColName(i) + |"|
Next
'打印表头end-------------------------------------------------------------------------------------
'根据文档中Couse的具体情况导出各个列:课程名称##分数##评语
intRow = 2
For i = 1 To dccTemp.Count
Set docTemp = dccTemp.GetNthDocument(i)
If Not docTemp Is Nothing Then
Print |varWorkSheet.Range("| + Chr(65 + 0) + Cstr(intRow) + |").FormulaR1C1 = "| + Cstr(i) + |"| '序号
Print |varWorkSheet.Range("| + Chr(65 + 1) + Cstr(intRow) + |").FormulaR1C1 = "| + docTemp.ID(0) + |"| '工号
'开始插入的列数
intCol = 2
'最多取30门课程
For m = 1 To 30
If docTemp.HasItem("Course_"+Cstr(m)) Then
strCouse = docTemp.GetFirstItem("Course_"+Cstr(m)).values(0)
strCouse = Replace(strCouse,"####","## ##")
varCouseList = Split(strCouse,"##")
Print |varWorkSheet.Range("| + Chr(65 + intCol + 0) + Cstr(intRow) + |").FormulaR1C1 = "| + replaceSpecailChr(varCouseList(0)) + |"|
Print |varWorkSheet.Range("| + Chr(65 + intCol + 1) + Cstr(intRow) + |").FormulaR1C1 = "| + replaceSpecailChr(varCouseList(1)) + |"|
Print |varWorkSheet.Range("| + Chr(65 + intCol + 2) + Cstr(intRow) + |").FormulaR1C1 = "| + replaceSpecailChr(varCouseList(2)) + |"|
End If
intCol = intCol + 3 '下一个课程信息插入的列数
Next
intRow = intRow + 1
Set docTemp = dccTemp.GetNextDocument(docTemp)
End If
Next
Print |varExcelApplication.Visible = true|
Print |history.back()|
Print |</script>|
导出:
CS版本
Dim ss As New NotesSession
Dim db As NotesDatabase
Dim vw As NotesView
Dim dcc As NotesDocumentCollection
Dim doc As NotesDocument
Dim excelApplication As Variant
Dim excelWorkbook As Variant
Dim excelSheet As Variant
Dim i As Integer,j As Integer
Dim strID As String
Dim varIDList As Variant
Set db = ss.Currentdatabase
Set vw = db.Getview("Search_PuzzleByPaperIDPersonID_View")
If vw Is Nothing Then
Exit sub
End If
'strID = "39129;33138;29288;41954;37319;27628;27342;21394;11008;39559;22215;22608;39562;21813;46628;21808;44371;30499;11007;21913;20692;8029;29189;44368;41956;39102;20374"
strID = "1048"
varIDList = Split(strID,";")
Set excelApplication = CreateObject("Excel.Application")
excelApplication.Visible = True
Set excelWorkbook = excelApplication.Workbooks.Add
Set excelSheet = excelWorkbook.Worksheets("Sheet1")
'根据选中要导出的字段来设置excle的第一列
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 = "历次保存时间"
i = 2
For j = 0 To UBound(varIDList)
Set doc = vw.Getdocumentbykey("Paper20110609133336DEVM-8HN8JJ"+"#*#"+varIDList(j),true)
If Not doc Is Nothing then
excelSheet.Cells(i,1).Value = doc.ID(0)
excelSheet.Cells(i,2).Value = doc.CName(0)
excelSheet.Cells(i,3).Value = doc.Depinfo(0)
excelSheet.Cells(i,4).Value = doc.PuzzleMark(0)
excelSheet.Cells(i,5).Value = CStr(doc.PuzzleStartDateTime(0))
excelSheet.Cells(i,6).Value = CStr(doc.PuzzleStartDateTime(0))
excelSheet.Cells(i,7).Value = Join(doc.Getitemvalue("$Revisions"),Chr(10))
i = i+1
End if
Next
'excelApplication.Quit
Set excelApplication = Nothing
BS版本
Dim ss As New NotesSession
Dim db As NotesDatabase
Dim dcctemp As NotesDocumentCollection
Dim doc As NotesDocument
Dim docTemp As NotesDocument
Dim vw As NotesView
Set db = ss.CurrentDatabase
Set doc = ss.DocumentContext
Set vw = db.GetView("Search_StudentByClassStage_View")
If vw Is Nothing Then
Exit Sub
End If
'获得本期第一个学员信息(通过有多少门课,确定应该多少列)
Set dccTemp = vw.GetAllDocumentsByKey(doc.BNType(0) + "#" + doc.ClassStage(0),True)
Set docTemp = dccTemp.GetFirstDocument
If docTemp Is Nothing Then
Print |<script>alert("无对应日期的数据")</script>|
Print |<script>history.back()</script>|
Exit Sub
End If
'初始化Excel组件
Print |<script lanuage="javascript">|
Print |var varExcelApplication = new ActiveXObject("Excel.Application");|
Print |var varWorkbook = varExcelApplication.Workbooks.Add();|
Print |var varWorkSheet = varWorkbook.Worksheets(1)|
Print |varWorkSheet.Name = "sheet1"|
Print |varWorkSheet.Rows("1:1").Select()|
Print |var varSelection = varExcelApplication.Selection|
Print |varSelection.Font.Name = "宋体"|
Print |varSelection.Font.Size = 10|
Print |varSelection.Font.Bold = true|
Print |varSelection.HorizontalAlignment = -4108|
Print |varWorkSheet.Columns("A:Z").Select|
Print |var varSelection = varExcelApplication.Selection|
Print |varSelection.NumberFormatLocal = "@"|
'打印表头start-----------------
strColName = "序号;工号"
For i = 1 To 30
strNum = Cstr(i)
If docTemp.HasItem("Course_"+strNum) Then
strColName = strColName + ";课程" + strNum + ";分数" + strNum + ";评语" + strNum
End If
Next
varColName = Split(strColName,";")
For i = 0 To Ubound(varColName)
Print |varWorkSheet.Range("| + Chr(65 + i) + |1").FormulaR1C1 = "| + varColName(i) + |"|
Next
'打印表头end-------------------------------------------------------------------------------------
'根据文档中Couse的具体情况导出各个列:课程名称##分数##评语
intRow = 2
For i = 1 To dccTemp.Count
Set docTemp = dccTemp.GetNthDocument(i)
If Not docTemp Is Nothing Then
Print |varWorkSheet.Range("| + Chr(65 + 0) + Cstr(intRow) + |").FormulaR1C1 = "| + Cstr(i) + |"| '序号
Print |varWorkSheet.Range("| + Chr(65 + 1) + Cstr(intRow) + |").FormulaR1C1 = "| + docTemp.ID(0) + |"| '工号
'开始插入的列数
intCol = 2
'最多取30门课程
For m = 1 To 30
If docTemp.HasItem("Course_"+Cstr(m)) Then
strCouse = docTemp.GetFirstItem("Course_"+Cstr(m)).values(0)
strCouse = Replace(strCouse,"####","## ##")
varCouseList = Split(strCouse,"##")
Print |varWorkSheet.Range("| + Chr(65 + intCol + 0) + Cstr(intRow) + |").FormulaR1C1 = "| + replaceSpecailChr(varCouseList(0)) + |"|
Print |varWorkSheet.Range("| + Chr(65 + intCol + 1) + Cstr(intRow) + |").FormulaR1C1 = "| + replaceSpecailChr(varCouseList(1)) + |"|
Print |varWorkSheet.Range("| + Chr(65 + intCol + 2) + Cstr(intRow) + |").FormulaR1C1 = "| + replaceSpecailChr(varCouseList(2)) + |"|
End If
intCol = intCol + 3 '下一个课程信息插入的列数
Next
intRow = intRow + 1
Set docTemp = dccTemp.GetNextDocument(docTemp)
End If
Next
Print |varExcelApplication.Visible = true|
Print |history.back()|
Print |</script>|
XML导入方式,更加节省资源
后台
Function GetListXML(vw As NotesView,strSelect As String) As Variant
%REM
功能:获得每一列的值
创建:ycy 2011-08-31
%END REM
On Error Goto ErrorHandle
Dim docTemp As NotesDocument
Dim intRow As Long
Dim strTitle As String
Dim varTitle As Variant
Dim i As Long
Dim intNum As Long
Dim strXML As String
'执行查询
intNum = vw.Ftsearch(strSelect,5000)
If intNum >= 5000 Then
strXML = |<excel><result>failue</result><memo>您导出结果数目超过5000,请缩小搜索范围后进行导出</memo></excel>|
GoTo ResultHandle
ElseIf intNum = 0 Then
strXML = |<excel><result>failue</result><memo>没有找到相关文档</memo></excel>|
GoTo ResultHandle
End If
'列名
strTitle = "排序列;姓名;。。。"
varTitle = Split(strTitle,";")
'开始组装查询结果XML
intRow = 1
strXML = strXML + |<excel>|
strXML = strXML + | <result>sucess</result>|
strXML = strXML + | <memo></memo>|
'---列名称
strXML = strXML + | <title>|
For i = 0 To UBound(varTitle)
strXML = strXML + | <col>| + varTitle(i) + |</col>|
Next
strXML = strXML + | </title>|
'---正文内容
Set docTemp = vw.Getfirstdocument()
While Not docTemp Is Nothing
strXML = strXML + |<row>|
strXML = strXML + | <no><![CDATA[| + docTemp.ID(0) + |]]></no>|
strXML = strXML + | <col><![CDATA[| + 。。。 + |]]></col>|
strXML = strXML + |</row>|
intRow = intRow + 1
Set docTemp = vw.Getnextdocument(docTemp)
Wend
strXML = strXML + |</excel>|
ResultHandle:
GetListXML = strXML
Exit Function
ErrorHandle:
Msgbox "导出-外包信息|agentOutputPerson的GetList错误在行:" + Cstr(Erl) + " 错误是:" + Cstr(Error)
End Function前台
//Ajax获得XML内容并写入Excel
//ycy 2011-11-01
var strURL = document.location.href
var intPos = strURL.indexOf(".nsf")
strURL = strURL.substring(0,intPos+4)
strURL = strURL + "/agentOutputITSoft?Openagent";
//加载特效
$("#spanLoading").html("<img src='loading.gif' style='margin-top:5px;'/>正在获取数据请稍后...")
var varData = {
CUserID:$("#CUserID").val(),
RndNum:Math.random()
}
$.ajax({
url: strURL,
dataType: 'xml',
type: 'GET',
data:varData,
timeout: 60000,
error: function(xml){
openPrompt("加载失败,请联系管理员");
//加载特效
$("#spanLoading").html("加载失败,请联系管理员")
},
success: function(xml){
var objXML = $(xml)
//如果获取Excel失败
if(objXML.find("result").text()=="failue"){
openPrompt(objXML.find("memo").text())
$("#spanLoading").html(objXML.find("memo").text())
return;
}
//获取成功则加载application
try{
var varExcelApplication = new ActiveXObject("Excel.Application");
}catch(e){
alert("请确认本机器已经安装Excel或浏览器安全设置: ActiveX相关项目设置为启用")
window.open("/sharedb.nsf/excelfaq?OpenPage","_blank")
history.back()
}
var varWorkbook = varExcelApplication.Workbooks.Add();
var varWorkSheet = varWorkbook.Worksheets(1)
varWorkSheet.Name = "sheet1"
varWorkSheet.Rows("1:1").Select()
var varSelection = varExcelApplication.Selection
varSelection.Font.Name = "宋体"
varSelection.Font.Size = 10
varSelection.Font.Bold = true
varSelection.HorizontalAlignment = -4108
varWorkSheet.Columns("A:ZZ").Select
var varSelection = varExcelApplication.Selection
varSelection.NumberFormatLocal = "@"
varExcelApplication.Visible = true
//获得标题
objXML.find("title col").each(function(i){
var objTitle = $(this)
varWorkSheet.Range(String.fromCharCode(65+i) + "1").FormulaR1C1 = objTitle.text()
})
//获得内容
objXML.find("row").each(function(i){
$(this).find("col").each(function(j){
var objCol = $(this)
varWorkSheet.Range(String.fromCharCode(65+j) + (i+2)).FormulaR1C1 = objCol.text()
})
})
//对指定列排序[第一列]
//var xlAscending = 1;
//var xlYes = 1;
//var xlSortRows=1;
//var xlPinYin= 1;
//var xlSortNormal =1;
//varWorkSheet.Range("A:Z").Sort(varWorkSheet.Columns("A"),xlAscending,null,null,null,null,null,xlYes,null,null,xlSortRows,xlPinYin,xlSortNormal,null,null);
//设置为10号字体
varWorkSheet.Columns("A:ZZ").EntireColumn.AutoFit()
varSelection.Font.Size = 10
//加载特效
$("#spanLoading").html("导出完毕")
}
});
399



被折叠的 条评论
为什么被折叠?



