我正在使用一年但现在我必须修改小脚本而且我是DXL
的新手。我在问题之前搜索过,但我不知道怎么做。
我必须开发一个脚本,分析同一个正式模块中的所有对象,从每个“对象文本”中提取由tab分隔的不同字符串,以便写入同一对象的其他不同属性。
正式模块内容已从Word导入。以这种方式,普通文本格式被定义为“对象文本”,并且每个标题样式与给定级别标题相关联。这样,每个对象都提供有对象标题或对象文本(但不能同时提供)。具有对象标题的对象不需要任何进一步的操作。但是对于提供了对象文本的对象,我必须从对象文本中提取一些由制表符分隔的属性。
例如,典型的对象文本可以是:
NNNN TEXT/TABLE/OLE OBJECT/ANY OTHER STRING (XXXXXX) (YYYYYY)
应用脚本后,应将其转换为:
Attribute 1: NNNN
Object Text: TEXT/TABLE/OLE OBJECT/ANY OTHER STRING
Attribute 2: XXXXXX
Attribute 3: YYYYYY
我有一个小脚本作为示例,但我整个上午都试图修改它以获得我需要,但我不能这样做:
Object o = current
//bool get_text(Object o) {return o."Object Heading" "" != ""}
string get_text(Object o)
{
if (o."Object Heading" "" != "")
return "Object Heading"
else
return "Object Text"
}
Regexp r_id = regexp "(http://0-9a-z/.+) "
for o in current Module do
{
string texto = o.(get_text(o))
if (r_id text)
{
o."Attribute 1" = textmatch 1
string input = richTextWithOle(o.(get_text(o)))
string output = cutRichText(input, 0, length(textmatch 1))
o.(get_text(o)) = richText(output)
}
}
答案 0 :(得分:2)
这是一个复杂的问题,但我想我已经弄明白了。感谢您发布此内容,因为我可能会发现它在将来也很有用。
我尝试了这个,似乎有效:
Object o
string get_text(Object o)
{
if (o."Object Heading" "" != "")
return "Object Heading"
else
return "Object Text"
}
char cTab = '\t' //The tab character to find
Buffer b = create
string tmp = "" //Needed to concatenate buffer parts
int offset = 0
for o in current Module do
{
string attr = get_text(o)
b = o.attr //Put the contents in the buffer
offset = contains(b, cTab) //Find the first tab
o."Attribute 1" = b[0:offset-1] //Set the first Attribute
b = b[offset+1:] //Remove the first attribute from the text
offset = contains(b, cTab)
if(offset > -1)
{
if(attr == "Object Heading") o.attr = b[0:offset-1]
b = b[offset+1:]
offset = contains(b, cTab)
if(offset > -1)
{
o."Attribute 2" = b[1:offset-2] //Set the second Attribute without the ()
b = b[offset+1:]
o."Attribute 3" = b[1:length(b)-2] //Set the third Attribute without the ()
} else {
o."Attribute 2" = b[1:length(b)-2] //Set the second Attribute without the ()
}
} else {
if(attr == "Object Heading") o.attr = b[0:]
}
if(attr == "Object Text")
{
b = richTextWithOle(o.attr) "" //This section removes the attributes from the contents without losing the rich text formatting and OLEs that may be present.
string word = o."Attribute 1"
offset = contains(b, word, 0)
tmp = b[0:offset-1] "" b[(offset+length(word)+5):]
b = tmp
word = "(" o."Attribute 2" ")"
offset = contains(b, word, 0)
if(offset > -1)
{
tmp = b[0:offset-6] "" b[offset+length(word):]
b = tmp
}
word = "(" o."Attribute 3" ")"
offset = contains(b, word, 0)
if(offset > -1)
{
tmp = b[0:offset-6] "" b[offset+length(word):]
}
o.attr = richText(tmp) //Set the Object Text or Heading
}
}
delete b //Release the buffer resources
如果您遇到任何麻烦或想要更详细地了解代码,请告诉我。
编辑:我更新了上面的代码来处理你提到的问题。现在应该全部设定。如果你有任何问题,请告诉我。