简体   繁体   English

Jenkins通过VBScript和参数化版本构建Excel

[英]Jenkins building Excel by VBScript and Parameterized build

Changing Excel spreadsheet cells through the usage of Jenkins 通过使用Jenkins更改Excel电子表格单元格

My seek in help is based on the link above. 我寻求帮助的依据是上面的链接。 I've been working on this for like 3 months, but still can't find a solution to it. 我已经为此工作了3个月,但仍然找不到解决方案。 I hope someone can help me out. 我希望有人能帮助我。

I want to achive the following: 我要实现以下目标:

  1. Get a specific excel sheet cell filled in by a value. 获取由值填充的特定Excel工作表单元格。 In my case the letter “Y” (See image 1) Image 1 在我的情况下,字母“ Y”(见图1) 图1
  2. Get the excel sheet cell filled with the letter "Y" through the selection from the Jenkins user interface(Parameterized build) (See image 2) Image 2 通过从Jenkins用户界面(参数化构建)中进行选择,获取填充有字母“ Y”的excel表格单元(见图2) 图2
  3. Get the letter "Y" be filled in a specfific cell inside the Excel Sheet. 将字母“ Y”填充到Excel工作表内的特定单元格中。 So when i select "Input for cell c3 as seen in image 2, i want to make sure that the letter "Y" gets excatlly filled inside Cell C3 in Excel and not other cells aswell. 因此,当我选择“如图2所示的单元格c3的输入”时,我想确保在Excel中的单元格C3中完全填充了字母“ Y”,而不是其他单元格。

So basically when I select “Testdata A” as Head and “Input for cel C3” as Sub, I want the value “Y” to be written inside cell C3 inside Excel. 因此,基本上,当我选择“ Testdata A”作为“ Head”并且选择“ Input for cel C3”作为“ Sub”时,我希望将值“ Y”写入Excel的单元格C3中。 Currently I managed to get the letter “Y” behind the names “input for cel C3”. 目前,我设法在名称“ cel C3的输入”后面得到字母“ Y”。 I do this with the code: 我用代码来做到这一点:

if (Head.equals("Testdata A")) {
  return ['Y':'Input for cel C3', 'N':'Input for cel C4', 'S': 'Input for cel C9', 'A':'Input for cel C10']
}

In my VBSCript I use a code to get the excel be filled by the value I select through Jenkins, but this code simply indicated that the cells C3, c4 and C5 all needs to get filled with 1 given argument.So even if i select "input for c3", all other cells will also get filled. 在我的VBSCript中,我使用了一个代码,使excel被我通过Jenkins选择的值填充,但是该代码只是表明C3,c4和C5单元格都需要填充1个给定的参数。因此,即使我选择“输入c3“,所有其他单元格也将被填充。 The code is: 代码是:

Dim xlApp
Dim wkBk
Dim wSheet
Dim y
Dim n

Set xlApp = CreateObject("Excel.Application")

xlApp.visible = True 
Set wkBk =  xlApp.Workbooks.Open("D:\location\of\excelFile\Excel.xlsb")
Set wSheet = wkBk.WorkSheets("Sheetname")

wSheet.Range("C3").Value =  Wscript.Arguments(0) 
wSheet.Range("C4").Value = Wscript.Arguments(0)
wSheet.Range("C5").Value = Wscript.Arguments(0)

wkBk.Save

I call my vbscript with the parameter argument as followed: 我用以下参数参数调用vbscript:

call D:\location\to\script\.vbs %Sub%

Guys/girls, help me out, How can i manage to fill a specific cell through a selection from Jenkins. 男孩/女孩,帮帮我,我如何通过詹金斯的选择来设法填补特定的牢房。

Based on your code above, it seems you need to split the input variable and iterate over it like this: 根据上面的代码,似乎您需要拆分输入变量并像这样迭代它:

Dim xlApp
Dim wkBk
Dim wSheet
Dim iLoop, setVal, setCell, myArguments, tempArray

Set xlApp = CreateObject("Excel.Application")

xlApp.visible = True 
Set wkBk =  xlApp.Workbooks.Open("D:\location\of\excelFile\Excel.xlsb")
Set wSheet = wkBk.WorkSheets("Sheetname")
myArguments = Split(Wscript.Arguments(0), ",") ' myArguments is now an array of the cells to be updated
For iLoop = 0 to UBound(myArguments)
    wSheet.Range(myArguments(iLoop)).Value = "Y" 
Next
wkBk.Save

Edit 1 : If you are always setting a "Y", then just pass in the Cells you want updated as a comma separated string eg "C1,C3,C5" . 编辑1:如果始终设置为“ Y”,则只需将要更新的单元格作为逗号分隔的字符串传递,例如"C1,C3,C5" The code above will set a Y in each of the cells passed into the script and not any others. 上面的代码将在传递到脚本的每个单元格(而不是其他任何单元格)中设置Y。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM