我需要您的帮助。循环访问数组值并生成不同的列名称输出
我想知道是否可以修改for循环,循环使用数组值并根据数组值输出列名,但也只有(1)出现单个项生成不同的列名称。下面是JavaScript代码输出到日期的画面:
这里是所需的输出。正如你所看到的,它在视觉上更吸引眼球而不需要重复使用。因为我将在列名后列出数字。
这里是有问题的Javascript代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
</style>
<script type="text/javascript">
function search_array(arr, str){
var searchExp = new RegExp(str,"gi");
return (searchExp.test(arr))?true:false;
}
function build_sheet() {
var Excel = new ActiveXObject("Excel.Application")
var Book = Excel.Workbooks.Add()
var Sheet = Book.ActiveSheet
var temp = "BNI to President","BNI to Director","BNI to Manager","BNA to President","BNA to Director","BNA to Manager"
var c = 2 /* Start position @ Column 2*/
for(var i = 0; i < temp.length; i++) {
if (search_array(temp[i], "BNI to") == true) {
Sheet.Cells(2,c).Value = "Briefing Notes (Info)"
}
if (search_array(temp[i], "BNA to") == true) {
Sheet.Cells(2,c).Value = "Briefing Notes (Approval)"
}
else {
Sheet.Cells(2,c).Value = temp[i]
}
++c
}
Excel.visible = true
Excel.quit()
Excel = null
}
</script>
</head>
<body>
</body>
</html>
'++ c' will be conditional i believe – charlietfl