【发布时间】:2020-10-13 15:33:53
【问题描述】:
我有一个 DXL 脚本,它应该遍历所选模块中的每个对象,并将基于对象数据的各种对象信息导出到 Microsoft Word 文件。它通常可以工作,但我遇到了一个问题,模块中的随机点数据没有粘贴到 Word 文档中。
有几个函数可以执行数据的导出,根据 DOORS 对象调用它们:
- put_heading_in_word( string s ) - 将标题编号和标题文本以更大的字体显示
- put_plain_text_in_word( string s ) - 将纯文本放入 Word 文档中
- put_new_line_in_word() - 在 Word 中放置一个回车
- put_object_text_in_word(Object ob) - 将传入的 DOORS 对象中的文本复制到 Word
以下是函数:
/****************************************************************************************
* put_new_line_in_word
*****************************************************************************************/
void put_new_line_in_word()
{
clear oleAutoArgs
put(oleAutoArgs, 1) // 0=wdCollapseEnd, 1=wdCollapseStart
oleMethod(objSel, "Collapse", oleAutoArgs)
setRichClip(richText "\n" )
oleMethod(objSel, "Paste")
}//put_new_line_in_word
/****************************************************************************************
* put_plain_text_in_word
*****************************************************************************************/
void put_plain_text_in_word(string s)
{
clear oleAutoArgs
put(oleAutoArgs, 1) // 0=wdCollapseEnd, 1=wdCollapseStart
oleMethod(objSel, "Collapse", oleAutoArgs)
copyToClipboard( s )
oleGet(objSel, "Font", oleFont)
olePut(oleFont, "Size", 11)
oleMethod(objSel, "Paste")
}//put_plain_text_in_word
/****************************************************************************************
* put_heading_in_word
*****************************************************************************************/
void put_heading_in_word( string s )
{
clear oleAutoArgs
put(oleAutoArgs, 1) // 0=wdCollapseEnd, 1=wdCollapseStart
oleMethod(objSel, "Collapse", oleAutoArgs)
copyToClipboard( s )
oleGet(objSel, "Font", oleFont)
olePut(oleFont, "Size", 18)
oleMethod(objSel, "Paste")
}//put_heading_in_word
/****************************************************************************************
* put_object_text_in_word
*****************************************************************************************/
void put_object_text_in_word(Object ob)
{
clear oleAutoArgs
put(oleAutoArgs, 1) // 0=wdCollapseEnd, 1=wdCollapseStart
oleMethod(objSel, "Collapse", oleAutoArgs)
// setRichClip(richText richText(ob."Object Text"))
setRichClip(richText(ob."Object Text"))
oleMethod(objSel, "Paste")
}//put_object_text_in_word
以下是如何使用它们的示例:
/****************************************************************************************
* Export_object
* This is called for each object
*****************************************************************************************/
void Export_object (Module m, Object obj)
{
// allows the the use of attribute exists
current = m
if ( isValidObject(obj))
{
temp_str = obj."Object Heading"
if(!null temp_str)
{
put_plian_text_in_word("ID: ")
put_plian_text_in_word(identifier(obj))
put_new_line_in_word
temp_str = number(obj)
put_heading_in_word(temp_str)
put_heading_in_word(" ")
temp_str = obj."Object Heading"
put_heading_in_word(temp_str)
put_new_line_in_word
}
else
{
put_plian_text_in_word("ID: ")
put_plian_text_in_word(identifier(obj))
put_new_line_in_word
temp_str = obj."Requirement"
put_plian_text_in_word("Requirement: " temp_str)
put_new_line_in_word
temp_str = obj."Derived"
put_plian_text_in_word("Derived: " temp_str)
put_new_line_in_word
temp_str = obj."DO-178 Level"
put_plian_text_in_word("DO-178 Level: " temp_str)
put_new_line_in_word
temp_str = obj."Safety"
put_plian_text_in_word("Safety: " temp_str)
put_new_line_in_word
put_plian_text_in_word("Object Text: ")
put_new_line_in_word
put_object_text_in_word(obj)
if(oleCopy(obj))
{
oleMethod(objSel, "Paste")
put_new_line_in_word
}
temp_str = obj."Justify"
put_plian_text_in_word("Justify: " temp_str)
put_new_line_in_word
}
}
}
我最初的想法是对 OLE 接口的访问过多并且事情被丢弃了,所以我创建了使用缓冲区变量的函数,我将各个字符串放入缓冲区并停止使用“put_new_line_in_word”函数,只是将 '\n' 放在缓冲区中。现在我只是丢失了更大的数据块,而且似乎并没有降低丢失数据的频率。
有什么想法吗?
【问题讨论】:
-
在 put_heading_in_word() 和 put_plain_text_in_word() 的基于缓冲区的版本中,我放置了“print()”语句以查看函数是否实际执行,并验证缓冲区具有正确的内容在函数被调用之后。
标签: ibm-doors