2

私は 1 年間使用していますが、今は小さなスクリプトを変更する必要があり、初心者です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 に答える