docx := new TSDocxFile(); //_test_readParagraphs(docx); _test_newfile(docx); //_test_addtable(docx); //_test_Properties(docx); //_test_picture(docx); Function _test_picture(docx); Begin [err, errmsg] := docx.NewFile(); if err then return echo 'Open Fail:', errmsg, '\n'; picture := TOfficeObj('TPicture'); picture.Descr := 'Hans Tan\'s Picture test'; readfile(rwbinary(), '', 'F:\\temp\\VS2010Ultim\\Setup\\banner.bmp', 0, 1024*1024, data); picture.Image := data; p := docx.AddPicture(picture, -1); v := docx.SaveAs('', 'f:\\temp\\p.docx'); println('Save={}', v); End; Function _test_Properties(docx); Begin f := 'F:\\temp\\test.docx'; [err, errmsg] := docx.OpenFile('', f); if err then return echo 'Open Fail:', errmsg, '\n'; core := docx.Properties(); core.Author := 'Hans Tan'; core.Modified := now(); docx.SaveAs('', 'f:\\temp\\core.docx'); End; Function _test_addtable(docx); Begin [err, errmsg] := docx.NewFile(); if err then return echo 'Open Fail:', errmsg, '\n'; data := array(("Name":"Small","Apple":2,"Orange":3,"Pear":3), ("Name":"Normal","Apple":5,"Orange":2,"Pear":4), ("Name":"Large","Apple":6,"Orange":7,"Pear":8)); tbl := docx.CreateTable(data, true, true); //tbl.TblPr.Style := 1; tbl := docx.InsertTable(tbl, -1); v := docx.SaveAs('', 'f:\\temp\\t.docx'); println('Save={}', v); End; Function _test_newfile(docx); Begin [err, errmsg] := docx.NewFile(); if err then return echo 'Open Fail:', errmsg, '\n'; paragraph := TOfficeObj('TParagraph'); paragraph.Run.Text := 'This is the 1 Line.'; p := docx.AddParagraph(paragraph, -1); p := docx.AddLineBreak(p); p := docx.AddLineBreak(p); paragraph.Run.Text := 'This is the 2 Line.'; p := docx.AddParagraph(paragraph, -1); p := docx.AddPageBreak(p); paragraph.Run.Text := 'This is the 3 Line.'; p := docx.AddParagraph(paragraph, -1); p := docx.AddColumnBreak(p); paragraph.Run.Text := ''; p := docx.AddParagraph(paragraph, -1); p.SetText('This is the 4 Line\nline5\nline6\nline7.'); v := docx.SaveAs('', 'f:\\temp\\new.docx'); println('Save={}', v); End; Function _test_readParagraphs(docx); Begin f := 'F:\\temp\\test.docx'; [err, errmsg] := docx.OpenFile('', f); if err then return echo 'Open Fail:', errmsg, '\n'; paragraph := TOfficeObj('TParagraph'); paragraph.Run.Text := 'New paragraph'; v := docx.AddParagraph(paragraph, 0); paragraphs := docx.Paragraphs(); println("AddParagraph={}", v); paragraphs[9].SetText('1、修改文字; 2、第2段; 3、第3段; 4、第4段。'); paragraphs := docx.Paragraphs(); for i:=0 to length(paragraphs)-1 do Begin println('Name={}, Text={}', paragraphs[i].Name(), paragraphs[i].Text()); End; tcnt := docx.TablesCount(); println('\n\nTableCount={}',tcnt); for i := 0 to tcnt-1 do Begin table := docx.GetTable(i); for j := 0 to table.Rows()-1 do Begin for k := 0 to table.Cols()-1 do Begin cell := table.Cell(j, k); if ifObj(cell) then Begin println('row={}, col={}, text={}', j, k, cell.Text()); continue; End; println('row={}, col={}, Cell=nil', j, k); End; End; End; println('all text={}, textArray={}', docx.Text(), docx.TextArray()); docx.SaveAs('', 'f:\\temp\\p.docx'); End;