OfficeVba/docx/TSDocxRange.tsf

447 lines
16 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Type TSDocxRange = class(TSVbaBase)
Uses TSDocxEnumerations;
public
Function Init(pbegin, pend, arr);
Function SetRangeArr(arr);
Function SetRangeFont();
Function CopyRunFormat(sourceRun, destRun);
private
range_arr_;
range_font_; // TSDocxFontRange
begin_;
end_;
public
Function AutoFormat();
Function Calculate();
Function CheckGrammar();
Function CheckSpelling(CustomDictionary, IgnoreUppercase, AlwaysSuggest, CustomDictionary2, CustomDictionary3, CustomDictionary4, CustomDictionary5, CustomDictionary6, CustomDictionary7, CustomDictionary8, CustomDictionary9, CustomDictionary10);
Function CheckSynonyms();
Function Collapse(Direction);
Function ComputeStatistics(Statistic);
Function ConvertHangulAndHanja(ConversionsMode, FastConversion, CheckHangulEnding, EnableRecentOrdering, CustomDictionary);
Function ConvertToTable(Separator, NumRows, NumColumns, InitialColumnWidth, Format, ApplyBorders, ApplyShading, ApplyFont, ApplyColor, ApplyHeadingRows, ApplyLastRow, ApplyFirstColumn, ApplyLastColumn, AutoFit, AutoFitBehavior, DefaultTableBehavior);
Function Copy();
Function CopyAsPicture();
Function Cut();
Function Delete(_Unit, Count);
Function DetectLanguage();
Function EndOf(_Unit, Extend);
Function Expand(_Unit);
Function ExportAsFixedFormat(OutputFileName, ExportFormat, OpenAfterExport, OptimizeFor, ExportCurrentPage, Item, IncludeDocProps, KeepIRM, CreateBookmarks, DocStructureTags, BitmapMissingFonts, UseISO19005_1, FixedFormatExtClassPtr);
Function ExportAsFixedFormat2(OutputFileName, ExportFormat, OpenAfterExport, OptimizeFor, ExportCurrentPage, Item, IncludeDocProps, KeepIRM, CreateBookmarks, DocStructureTags, BitmapMissingFonts, UseISO19005_1, OptimizeForImageQuality, FixedFormatExtClassPtr);
Function ExportFragment(FileName, Format);
Function GetSpellingSuggestions(CustomDictionary, IgnoreUppercase, MainDictionary, SuggestionMode, CustomDictionary2, CustomDictionary3, CustomDictionary4, CustomDictionary5, CustomDictionary6, CustomDictionary7, CustomDictionary8, CustomDictionary9, CustomDictionary10);
Function GoTo(What, Which, Count, Name);
Function GoToEditableRange(EditorID);
Function GoToNext(What);
Function GoToPrevious(What);
Function ImportFragment(FileName, MatchDestination);
Function InRange(Range);
Function InsertAfter(Text);
Function InsertAlignmentTab(Alignment, RelativeTo);
Function InsertAutoText(Text);
Function InsertBefore(Text);
Function InsertBreak(Type);
Function InsertCaption(_Label, Title, TitleAutoText, Position, ExcludeLabel);
Function InsertCrossReference(ReferenceType, ReferenceKind, ReferenceItem, InsertAsHyperlink, IncludePosition, SeparateNumbers, SeparatorString);
Function InsertDatabase(Format, Style, LinkToSource, Connection, SQLStatement, SQLStatement1, PasswordDocument, PasswordTemplate, WritePasswordDocument, WritePasswordTemplate, DataSource, From_, To_, IncludeFields);
Function InsertDateTime(DateTimeFormat, InsertAsField, InsertAsFullWidth, DateLanguage, CalendarType);
Function InsertFile(FileName, Range, ConfirmConversions, Link, Attachment);
Function InsertParagraph();
Function InsertParagraphAfter();
Function InsertParagraphBefore();
Function InsertSymbol(CharacterNumber, Font, Unicode, Bias);
Function InsertXML(XML, Transform);
Function InStory(Range);
Function IsEqual(Range);
Function LookupNameProperties();
Function ModifyEnclosure(Style, Symbol, EnclosedText);
Function Move(_Unit, Count);
Function MoveEnd(_Unit, Count);
Function MoveEndUntil(Cset, Count);
Function MoveEndWhile(Cset, Count);
Function MoveStart(_Unit, Count);
Function MoveStartUntil(Cset, Count);
Function MoveStartWhile(Cset, Count);
Function MoveUnti(Cset, Count);
Function MoveWhile(Cset, Count);
Function Nex(_Unit, Count);
Function NextSubdocument();
Function Paste();
Function PasteAndFormat(Type);
Function PasteAppendTable();
Function PasteAsNestedTable();
Function PasteExcelTable(LinkedToExcel, WordFormatting, RTF);
Function PasteSpecial(IconIndex, Link, Placement, DisplayAsIcon, DataType, IconFileName, IconLabel);
Function PhoneticGuide(Text, Alignment, Raise_, FontSize, FontName);
Function Previous(_Unit, Count);
Function PreviousSubdocument();
Function Relocate(Direction);
Function Select();
Function SetListLevel(Level);
Function SetRange(Start, _End);
Function Sort(ExcludeHeader, FieldNumber, SortFieldType, SortOrder, FieldNumber2, SortFieldType2, SortOrder2, FieldNumber3, SortFieldType3, SortOrder3, SortColumn, Separator, CaseSensitive, BidiSort, IgnoreThe, IgnoreKashida, IgnoreDiacritics, IgnoreHe, LanguageID);
Function SortAscending();
Function SortByHeadings(SortFieldType, SortOrder, CaseSensitive, BidiSort, IgnoreThe, IgnoreKashida, IgnoreDiacritics, IgnoreHe, LanguageID);
Function SortDescending();
Function StartOf(_Unit, Extend);
Function TCSCConverter(WdTCSCConverterDirection, CommonTerms, UseVariants);
Function WholeStory();
property Bold read ReadBold write WriteBold;
property BoldBi read ReadBoldBi write WriteBoldBi;
property BookmarkID read ReadBookmarkID;
property Bookmarks read ReadBookmarks;
property Borders read ReadBorders;
property Case_ read ReadCase write WriteCase;
property Cells read ReadCells;
property Characters read ReadCharacters;
property CharacterStyle read ReadCharacterStyle;
property CharacterWidth read ReadCharacterWidth write WriteCharacterWidth;
property Columns read ReadColumns;
property CombineCharacters read ReadCombineCharacters write WriteCombineCharacters;
property Comments read ReadComments;
property Conflicts read ReadConflicts;
property ContentControls read ReadContentControls;
property DisableCharacterSpaceGrid read ReadDisableCharacterSpaceGrid write WriteDisableCharacterSpaceGrid;
property Document read ReadDocument;
property Duplicate read ReadDuplicate;
property Editors read ReadEditors;
property EmphasisMark read ReadEmphasisMark write WriteEmphasisMark;
property _End read ReadEnd write WriteEnd;
property EndnoteOptions read ReadEndnoteOptions;
property Endnotes read ReadEndnotes;
property EnhMetaFileBits read ReadEnhMetaFileBits;
property Fields read ReadFields;
property Find read ReadFind;
property FitTextWidth read ReadFitTextWidth write WriteFitTextWidth;
property Font read ReadFont;
property FootnoteOptions read ReadFootnoteOptions;
property Footnotes read ReadFootnotes;
property FormattedText read ReadFormattedText write WriteFormattedText;
property FormFields read ReadFormFields;
property Frames read ReadFrames;
property GrammarChecked read ReadGrammarChecked write WriteGrammarChecked;
property GrammaticalErrors read ReadGrammaticalErrors;
property HighlightColorIndex read ReadHighlightColorIndex write WriteHighlightColorIndex;
property HorizontalInVertical read ReadHorizontalInVertical write WriteHorizontalInVertical;
property HTMLDivisions read ReadHTMLDivisions;
property Hyperlinks read ReadHyperlinks;
property ID read ReadID write WriteID;
property Information read ReadInformation;
property InlineShapes read ReadInlineShapes;
property IsEndOfRowMark read ReadIsEndOfRowMark;
property Italic read ReadItalic write WriteItalic;
property ItalicBi read ReadItalicBi write WriteItalicBi;
property Kana read ReadKana write WriteKana;
property LanguageDetected read ReadLanguageDetected write WriteLanguageDetected;
property LanguageID read ReadLanguageID write WriteLanguageID;
property LanguageIDFarEast read ReadLanguageIDFarEast write WriteLanguageIDFarEast;
property LanguageIDOther read ReadLanguageIDOther write WriteLanguageIDOther;
property ListFormat read ReadListFormat;
property ListParagraphs read ReadListParagraphs;
property ListStyle read ReadListStyle;
property Locks read ReadLocks;
property NextStoryRange read ReadNextStoryRange;
property NoProofing read ReadNoProofing write WriteNoProofing;
property OMaths read ReadOMaths;
property Orientation read ReadOrientation write WriteOrientation;
property PageSetup read ReadPageSetup;
property ParagraphFormat read ReadParagraphFormat write WriteParagraphFormat;
property Paragraphs read ReadParagraphs;
property ParagraphStyle read ReadParagraphStyle;
property ParentContentControl read ReadParentContentControl;
property PreviousBookmarkID read ReadPreviousBookmarkID;
property ReadabilityStatistics read ReadReadabilityStatistics;
property Revisions read ReadRevisions;
property Rows read ReadRows;
property Scripts read ReadScripts;
property Sections read ReadSections;
property Sentences read ReadSentences;
property Shading read ReadShading;
property ShapeRange read ReadShapeRange;
property ShowAll read ReadShowAll write WriteShowAll;
property SpellingChecked read ReadSpellingChecked write WriteSpellingChecked;
property SpellingErrors read ReadSpellingErrors;
property Start read ReadStart write WriteStart;
property StoryLength read ReadStoryLength;
property StoryType read ReadStoryType;
property Style read ReadStyle write WriteStyle;
property Subdocuments read ReadSubdocuments;
property SynonymInfo read ReadSynonymInfo;
property Tables read ReadTables;
property TableStyle read ReadTableStyle;
property Text read ReadText write WriteText;
property TextRetrievalMode read ReadTextRetrievalMode write WriteTextRetrievalMode;
property TextVisibleOnScreen read ReadTextVisibleOnScreen;
property TopLevelTables read ReadTopLevelTables;
property TwoLinesInOne read ReadTwoLinesInOne write WriteTwoLinesInOne;
property Underline read ReadUnderline write WriteUnderline;
property Updates read ReadUpdates;
property WordOpenXML read ReadWordOpenXML;
property Words read ReadWords;
property XML read ReadXML;
Function ReadXML();
Function ReadWords();
Function ReadWordOpenXML();
Function ReadUpdates();
Function WriteUnderline(value);
Function ReadUnderline();
Function WriteTwoLinesInOne(value);
Function ReadTwoLinesInOne();
Function ReadTopLevelTables();
Function ReadTextVisibleOnScreen();
Function WriteTextRetrievalMode(value);
Function ReadTextRetrievalMode();
Function WriteText(value);
Function ReadText();
Function ReadTableStyle();
Function ReadTables();
Function ReadSynonymInfo();
Function ReadSubdocuments();
Function WriteStyle(value);
Function ReadStyle();
Function ReadStoryType();
Function ReadStoryLength();
Function WriteStart(value);
Function ReadStart();
Function ReadSpellingErrors();
Function WriteSpellingChecked(value);
Function ReadSpellingChecked();
Function WriteShowAll(value);
Function ReadShowAll();
Function ReadShapeRange();
Function ReadShading();
Function ReadSentences();
Function ReadSections();
Function ReadScripts();
Function ReadRows();
Function ReadRevisions();
Function ReadReadabilityStatistics();
Function ReadPreviousBookmarkID();
Function ReadParentContentControl();
Function ReadParagraphStyle();
Function ReadParagraphs();
Function WriteParagraphFormat(value);
Function ReadParagraphFormat();
Function ReadPageSetup();
Function WriteOrientation(value);
Function ReadOrientation();
Function ReadOMaths();
Function WriteNoProofing(value);
Function ReadNoProofing();
Function ReadNextStoryRange();
Function ReadLocks();
Function ReadListStyle();
Function ReadListParagraphs();
Function ReadListFormat();
Function WriteLanguageIDOther(value);
Function ReadLanguageIDOther();
Function WriteLanguageIDFarEast(value);
Function ReadLanguageIDFarEast();
Function WriteLanguageID(value);
Function ReadLanguageID();
Function WriteLanguageDetected(value);
Function ReadLanguageDetected();
Function WriteKana(value);
Function ReadKana();
Function WriteItalicBi(value);
Function ReadItalicBi();
Function WriteItalic(value);
Function ReadItalic();
Function ReadIsEndOfRowMark();
Function ReadInlineShapes();
Function ReadInformation();
Function WriteID(value);
Function ReadID();
Function ReadHyperlinks();
Function ReadHTMLDivisions();
Function WriteHorizontalInVertical(value);
Function ReadHorizontalInVertical();
Function WriteHighlightColorIndex(value);
Function ReadHighlightColorIndex();
Function ReadGrammaticalErrors();
Function WriteGrammarChecked(value);
Function ReadGrammarChecked();
Function ReadFrames();
Function ReadFormFields();
Function WriteFormattedText(value);
Function ReadFormattedText();
Function ReadFootnotes();
Function ReadFootnoteOptions();
Function ReadFont();
Function WriteFitTextWidth(value);
Function ReadFitTextWidth();
Function ReadFind();
Function ReadFields();
Function ReadEnhMetaFileBits();
Function ReadEndnotes();
Function ReadEndnoteOptions();
Function WriteEnd(value);
Function ReadEnd();
Function WriteEmphasisMark(value);
Function ReadEmphasisMark();
Function ReadEditors();
Function ReadDuplicate();
Function ReadDocument();
Function WriteDisableCharacterSpaceGrid(value);
Function ReadDisableCharacterSpaceGrid();
Function ReadContentControls();
Function ReadConflicts();
Function ReadComments();
Function WriteCombineCharacters(value);
Function ReadCombineCharacters();
Function ReadColumns();
Function WriteCharacterWidth(value);
Function ReadCharacterWidth();
Function ReadCharacterStyle();
Function ReadCharacters();
Function ReadCells();
Function WriteCase(value);
Function ReadCase();
Function ReadBorders(index);
Function ReadBookmarks();
Function ReadBookmarkID();
Function WriteBoldBi(value);
Function ReadBoldBi();
Function WriteBold(value);
Function ReadBold();
End;
// ============== 实现 ================= //
Function TSDocxRange.Init(pbegin, pend, arr);
Begin
range_arr_ := arr;
begin_ := pbegin;
end_ := pend;
range_font_ := new TSDocxFontRange(self.Application, self.Creator, self);
range_font_.Init(range_arr_);
End;
Function TSDocxRange.SetRangeArr(arr);
Begin
range_arr_ := arr;
range_font_ := new TSDocxFontRange(self.Application, self.Creator, self);
range_font_.Init(range_arr_);
End;
Function TSDocxRange.CopyRunFormat(sourceRun, destRun);
Begin
rpr := sourceRun.FirstChildElement("w:rPr");
marshal := rpr.Marshal();
node := class(TSXml).GetNode(destRun, "w:rPr", "first");
class(TSXml).UpdateNode(node, marshal[0]["attribute"], marshal[0]["children"]);
End;
// function
Function TSDocxRange.InsertAfter(Text);
Begin
paragraph := range_arr_[length(range_arr_)-1]["tparagraph"];
if paragraph.Empty() then
begin
run := paragraph.AppendRun();
run.AddText(Text);
paragraph.CopyRunFormat(false, run.Root());
end
else begin
trun := range_arr_[length(range_arr_)-1]["trun"];
run := paragraph.AppendRun(trun);
run.AddText(Text);
CopyRunFormat(trun.Root(), run.Root());
end
End;
Function TSDocxRange.InsertBefore(Text);
Begin
paragraph := range_arr_[0]["tparagraph"];
if paragraph.Empty() then
begin
run := paragraph.AppendRun();
run.AddText(Text);
paragraph.CopyRunFormat(false, run.Root());
end
else begin
trun := range_arr_[0]["trun"];
node := trun.Root().PrevElement();
if not ifObj(node) then node := trun.Root();
run := paragraph.PrependRun(trun);
run.AddText(Text);
CopyRunFormat(node, run.Root());
end
End;
Function TSDocxRange.InsertBreak(Type);
Begin
pf := function(t, c);
begin
range_arr_[0] := class(TSWdCommon).SplitSingleRangeRun(range_arr_[0]);
run := range_arr_[0]["trun"];
run.Br.Type := t;
run.Br.Clear := c;
run.ClearText();
run.Apply();
end
if ifnil(Type) then Type := TSDocxEnumerations.wdPageBreak();
case Type of
TSDocxEnumerations.wdColumnBreak():
return;
TSDocxEnumerations.wdLineBreak():
##pf("textWrapping", nil);
TSDocxEnumerations.wdLineBreakClearLeft():
##pf("textWrapping", "left");
TSDocxEnumerations.wdLineBreakClearRight():
##pf("textWrapping", "right");
TSDocxEnumerations.wdPageBreak(): // TODO需要切割段落
return;
TSDocxEnumerations.wdSectionBreakContinuous():
return;
TSDocxEnumerations.wdSectionBreakEvenPage():
return;
TSDocxEnumerations.wdSectionBreakNextPage():
return;
TSDocxEnumerations.wdSectionBreakOddPage():
return;
TSDocxEnumerations.wdTextWrappingBreak():
##pf("textWrapping", "all");
end;
End;
// property
Function TSDocxRange.WriteBoldBi(value);
Begin
range_font_.BoldBi := value;
End;
Function TSDocxRange.ReadBoldBi();
Begin
return range_font_.BoldBi;
End;
Function TSDocxRange.WriteBold(value);
Begin
range_font_.Bold := value;
End;
Function TSDocxRange.ReadBold();
Begin
return range_font_.Bold;
End;
Function TSDocxRange.ReadFont();
Begin
return range_font_;
End;
Function TSDocxRange.ReadBorders(index);
Begin
borders_obj := new TSDocxBordersRange(self.Application, self.Creator, self);
borders_obj.Init(range_arr_);
return ifnil(index) ? borders_obj : borders_obj.Item(index);
End;