【问题标题】:Exporting DOORS Objects to csv files with dxl wont write all objects?使用 dxl 将 DOORS 对象导出到 csv 文件不会写入所有对象?
【发布时间】:2015-07-23 00:57:54
【问题描述】:

我为 DOORS 9.5 编写了一个脚本,该脚本在 DOORS 模块中查找特定对象并将它们写入 csv 文件。然而,在特定数量的行之后,它停止写入 csv 文件,我只得到了我请求的对象的一半。 我正在使用我在互联网上找到的字符串替换功能。那么这可能是问题所在,还是 dxl 可以在 csv 文件中写入某种最大值?

如果有人能帮我解决这个问题会非常好,因为我在互联网上找不到任何解决方案或理解为什么这不起作用。

// String replacement function
string replace (string sSource, string sSearch, string sReplace) 
{
int iLen = length sSource
if (iLen == 0) return ""

int iLenSearch = length(sSearch)

if (iLenSearch == 0) 
{ 
    print "search string must not be empty"
    return "" 
}

// read the first char for latter comparison -> speed optimization
char firstChar = sSearch[0]

Buffer s = create() 
int pos = 0, d1,d2;    
int i

while (pos < iLen) { 
    char ch = sSource[pos]; 
    bool found = true

    if (ch != firstChar) {pos ++; s+= ch; continue}
    for (i = 1; i < iLenSearch; i++) 
       if (sSource[pos+i] != sSearch[i]) { found = false; break }
    if (!found) {pos++; s+= ch; continue}
    s += sReplace
    pos += iLenSearch
}

string result = stringOf s
delete s
return result
}

Module m = read(modulePath, false)
Object o
string s
string eval

Stream outfile = write("D:\\Python\\Toolbeta\\data\\modules\\test.csv")
for o in m do
{
eval = o."Evaluation Spec Filter"
if(eval == "Evaluation Step Object")
{
    s = o."Object Text"
    s = replace(s,"\n","\\n")
outfile2 << o."HierarchyNumber" ";" s "\n"
}
}
close outfile

【问题讨论】:

    标签: python string csv ibm-doors


    【解决方案1】:

    我终于找到了解决问题的方法(我知道替换功能有点糟糕^^)。 dxl 脚本似乎有一个内部计时器。当计时器到时,即使进程仍在执行,脚本也会自动结束。所以我的脚本总是在 x 秒后停止,这就是我从未在我的 csv 文件中获得所有数据的原因。 如果您有同样的问题,请尝试pragma runLim,0。它将计时器设置为无限制。您还可以通过将 0 替换为任意数字来选择计时器。 (对于我的目的,2000000 最适合)。

    感谢所有答案和帮助

    【讨论】:

      【解决方案2】:

      据我所知,输出到 CSV 没有行数限制。

      但我确实在您的替换功能中看到了一些奇怪的东西。您的 sSearch 变量始终为 \n,就 DOORS 而言,它是 1 个字符(回车)。但在以下行 i=1

      if (sSource[pos+i] != sSearch[i]) { found = false; break }
      

      sSearch1 位置没有任何字符,因为字符串数组从0 开始。

      我认为您需要将 for 循环更改为:

      for (i = 0; i < iLenSearch; i++)
      

      我的猜测是您的脚本在第一次找到带有回车符的对象时失败了。

      如果有帮助,请告诉我,祝你好运!

      【讨论】:

        【解决方案3】:

        在将对象文本输出到 CSV 时,您必须注意许多问题。您是否正在处理替换逗号,或者至少引用文本?如果对象文本中有一个 OLE 怎么办?等等。

        如果您手动执行此操作,我建议您设置一个视图,其中包含您希望作为列查看的属性和一个过滤器以仅包含您希望查看的对象,然后使用本机 DOORS 导出到 Excel(模块窗口:文件 > 导出 > Microsoft Office > Excel)。如果您确实需要 CSV,则可以从 Excel 中另存为 CSV。

        如果您使用脚本自动执行此操作,我建议您使用 Excel 的 DXL 库,例如:http://www.baselinesinc.com/dxl-repository/

        (但请注意,在 Windows 计划任务中使用 Excel 会出现问题。)

        如果您无权访问 Excel,那么您可能会在网上寻找一些用于写入 CSV 的 C 代码,并以此为基础构建您的 DXL。

        希望对您有所帮助。

        编辑:另外,这里有一个很好的转义函数链接:https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014627043

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-22
          • 1970-01-01
          • 1970-01-01
          • 2020-02-02
          相关资源
          最近更新 更多