2

我使用了一年,但现在我必须修改小脚本,而且我是DXL. 我已经搜索过之前的问题,但我不知道我该怎么做。

我必须开发一个脚本来分析同一正式模块中的所有对象,以从每个“对象文本”中提取由制表符分隔的不同字符串,以写入同一对象的其他不同属性。

正式的模块内容已从 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) 
    }

}
4

1 回答 1

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

让我知道这是否会给您带来任何麻烦,或者您是否想要对代码进行更详细的解释。

编辑:我更新了上面的代码来处理你提到的问题。现在应该全部设置好了。让我知道您是否还有其他问题。

于 2012-11-06T14:41:08.630 回答