本文整理汇总了C#中Document.Range方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Range方法的具体用法?C# Document.Range怎么用?C# Document.Range使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.Range方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMassMailing
static void CreateMassMailing(ICollection<WordStatementInfo> statements, Document sourceDoc, Document doc, IProgressReporter progress)
{
using (new ClipboardScope()) {
sourceDoc.Range().Copy();
int pageSize = sourceDoc.ContentControls.Count;
var people = statements.Select(s => s.Person).Distinct().OrderBy(p => p.LastName).ToArray();
int pageCount = (int)Math.Ceiling(people.Length / (float)pageSize);
progress.Maximum = pageCount;
var range = doc.Range();
for (int i = 0; i < pageCount; i++) {
if (progress.WasCanceled) return;
progress.Progress = i;
range.Collapse(WdCollapseDirection.wdCollapseEnd);
range.Paste();
}
new MassMailingGenerator(people).Populate(doc.Range());
}
}
示例2: InsertEmptyParagraph
private Range InsertEmptyParagraph(Document document, bool stripFormatting)
{
object start = 0, end = 0;
Range rng = document.Range(ref start, ref end);
if (rng.Tables.Count > 0)
{
// We have a table at the start of the email so add an empty para for our text
Table table = rng.Tables[1];
Row row = table.Rows[1];
//rng.Tables[1].Split(ref row); this does not work, get bad parameter exception! So ...
table.Rows.Add(row);
row = table.Rows[1];
row.Cells.Merge();
row.ConvertToText(WdTableFieldSeparator.wdSeparateByDefaultListSeparator);
}
else
{
rng.InsertParagraphBefore();
}
if (stripFormatting)
{
// Remove unwanted formating
rng.Collapse(WdCollapseDirection.wdCollapseStart);
rng.HighlightColorIndex = WdColorIndex.wdNoHighlight; // get rid of any highlight
rng.ListFormat.RemoveNumbers(); // get rid of any list numbers and bullets
rng.Borders = document.Styles[WdBuiltinStyle.wdStyleNormal].Borders;
SetShading(rng.Shading, document.Styles[WdBuiltinStyle.wdStyleNormal].Shading);
SetFont(rng.Font, document.Styles[WdBuiltinStyle.wdStyleNormal].Font, true);
// set font to default values
}
return rng;
}
示例3: ParseFieldCode
private void ParseFieldCode(Document document, FieldCodeSearchModel code,
ICollection<FieldCodeSummaryModel> analysisData)
{
var text = document.Range().Text;
Debug.WriteLine("Text is: {0}, Regex is: {1}", text, code.Regex);
var matches = Regex.Matches(text, code.Regex, RegexOptions.IgnoreCase);
analysisData.Add(
new FieldCodeSummaryModel
{
ColumnName = code.FriendlyName,
Value = matches.Count
});
}
示例4: EditDocArg
private static string EditDocArg(string newValue, string oldValue, Document wordDoc)
{
var result = "";
try
{
var wfnd = wordDoc.Range().Find;
wfnd.Text = oldValue;
wfnd.ClearFormatting();
if (wfnd.Execute(ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, ref _mis, newValue, RpAll, ref _mis, ref _mis, ref _mis, ref _mis))
{
Console.WriteLine("Find");
}
}
catch (Exception ex)
{
result = ex.Message;
Console.WriteLine("Error:" + ex.Message);
}
return result;
}
示例5: GetDocText
public string GetDocText(string docfile)
{
Object filename = docfile;
Object confirmConversions = Type.Missing;
Object readOnly = Type.Missing;
Object addToRecentFiles = Type.Missing;
Object passwordDocument = Type.Missing;
Object passwordTemplate = Type.Missing;
Object revert = Type.Missing;
Object writePasswordDocument = Type.Missing;
Object writePasswordTemplate = Type.Missing;
Object format = Type.Missing;
Object encoding = Type.Missing;
Object visible = Type.Missing;
Object openConflictDocument = Type.Missing;
Object openAndRepair = Type.Missing;
Object documentDirection = Type.Missing;
Object noEncodingDialog = Type.Missing;
Microsoft.Office.Interop.Word.Application Progr = new Microsoft.Office.Interop.Word.Application();
Progr.Documents.Open(ref filename,
ref confirmConversions,
ref readOnly,
ref addToRecentFiles,
ref passwordDocument,
ref passwordTemplate,
ref revert,
ref writePasswordDocument,
ref writePasswordTemplate,
ref format,
ref encoding,
ref visible,
ref openConflictDocument,
ref openAndRepair,
ref documentDirection,
ref noEncodingDialog);
Document Doc = new Document();
Doc = Progr.Documents.Application.ActiveDocument;
object start = 0;
object stop = Doc.Characters.Count;
Range Rng = Doc.Range(ref start, ref stop);
string result = Rng.Text;
object sch = Type.Missing;
object aq = Type.Missing;
object ab = Type.Missing;
Progr.Quit(ref sch, ref aq, ref ab);
return result;
}
示例6: CreatePersonalizedMailing
static void CreatePersonalizedMailing(ICollection<WordStatementInfo> statements, Document sourceDoc, Document doc, IProgressReporter progress)
{
using (new ClipboardScope()) {
var populator = new MailingPopulator();
sourceDoc.Range().Copy();
Range range = doc.Range();
progress.Maximum = statements.Count;
int i = 0;
foreach (var person in statements.GroupBy(s => s.Person)) {
if (progress.WasCanceled) return;
progress.Progress = i;
range.Collapse(WdCollapseDirection.wdCollapseEnd);
range.Paste();
populator.Populate(range, person);
foreach (Shape shape in range.ShapeRange)
populator.Populate(shape.TextFrame.TextRange, person);
i++;
}
}
}
示例7: createBlank
protected bool createBlank(string fileName)
{
try {
doc = app.Documents.Open(fileName, Visible: true, ReadOnly: false);
doc.Select();
doc.PageSetup.LeftMargin = 60;
doc.PageSetup.TopMargin = 30;
doc.PageSetup.BottomMargin = 30;
doc.PageSetup.RightMargin = 30;
doc.PageSetup.FooterDistance = 30;
doc.PageSetup.HeaderDistance = 0;
int x=doc.Range().Tables.Count;
Table first=doc.Range().Tables[1];
resetTable(first);
first.Range.Font.Size = 13;
first.Columns.Add();
first.AutoFormat(ApplyBorders: false, ApplyShading: false, ApplyFont: false, ApplyColor: false, ApplyHeadingRows: false,
ApplyLastRow: false, ApplyFirstColumn: false, AutoFit: false, ApplyLastColumn: false);
first.Rows[1].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
Table tab =first.Rows[1].Cells[1].Range.Tables.Add(first.Rows[1].Cells[1].Range, 1, 4);
tab.Rows.Add();
tab.Rows.Add();
tab.Rows.Add();
tab.Rows[1].Cells[1].Merge(tab.Rows[1].Cells[2]);
tab.Rows[1].Cells[1].Merge(tab.Rows[1].Cells[2]);
tab.Rows[1].Cells[1].Merge(tab.Rows[1].Cells[2]);
tab.Rows[1].Cells[1].Range.Text = "Бланк переключений";
tab.Rows[2].Cells[4].Range.Paragraphs.Add();
tab.Rows[2].Cells[4].Range.Paragraphs.First.Range.Select();
app.Selection.Range.Fields.Add(app.Selection.Range, Text: "Date ");
tab.Rows[2].Cells[4].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
tab.Rows[2].Cells[1].Range.Text = "№";
tab.Rows[2].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
tab.Rows[2].Cells[2].Range.Text = "______";
tab.Rows[2].Cells[2].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
tab.Rows[2].Cells[2].Range.Font.Color = WdColor.wdColorWhite;
tab.Rows[2].Cells[3].Range.Text = "/" + getNumber(fileName);
tab.Rows[2].Cells[3].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
tab.Rows[2].Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle;
tab.Rows[2].Cells[1].PreferredWidthType = WdPreferredWidthType.wdPreferredWidthAuto;
tab.Rows[2].Cells[2].PreferredWidthType = WdPreferredWidthType.wdPreferredWidthAuto;
tab.Rows[2].Cells[3].PreferredWidthType = WdPreferredWidthType.wdPreferredWidthAuto;
tab.Rows[2].Cells[4].PreferredWidthType = WdPreferredWidthType.wdPreferredWidthAuto;
tab.Rows[3].Cells[1].Merge(tab.Rows[3].Cells[2]);
tab.Rows[3].Cells[1].Merge(tab.Rows[3].Cells[2]);
tab.Rows[3].Cells[1].Merge(tab.Rows[3].Cells[2]);
tab.Rows[3].Cells[1].Range.Text = "Начало ____час____мин";
tab.Rows[3].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
tab.Rows[4].Cells[1].Merge(tab.Rows[4].Cells[2]);
tab.Rows[4].Cells[1].Merge(tab.Rows[4].Cells[2]);
tab.Rows[4].Cells[1].Merge(tab.Rows[4].Cells[2]);
tab.Rows[4].Cells[1].Range.Text = "Конец ____час____мин";
tab.Rows[4].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
/*tab.Rows[2].Cells[1].PreferredWidth = 20;
tab.Rows[2].Cells[2].PreferredWidth = 50;
tab.Rows[2].Cells[3].PreferredWidth = 30;*/
first.Rows[1].Cells[2].Range.InsertAfter("Филиал ОАО \"РусГидро\"\n - \"Воткинская ГЭС\"");
first.AutoFitBehavior(WdAutoFitBehavior.wdAutoFitWindow);
Table last=doc.Range().Tables[doc.Range().Tables.Count];
resetTable(last);
last.Range.Font.Size = 12;
last.TopPadding = 10;
last.Columns.Add();
last.Rows.Add();
last.Rows.Add();
last.Rows.Add();
last.AutoFormat(ApplyBorders: false, ApplyShading: false, ApplyFont: false, ApplyColor: false, ApplyHeadingRows: false,
ApplyLastRow: false, ApplyFirstColumn: false, AutoFit: false, ApplyLastColumn: false);
last.Rows[1].Cells[1].Range.Text = "Типовой бланк переключений проверен, соответствует схемам, переключения в указанной в нем последовательности могут быть выполнены";
last.Rows[2].Cells[1].Range.Text = "Переключения разрешаю (НСС):";
last.Rows[2].Cells[2].Range.Text = "_________/_____________________/";
last.Rows[3].Cells[1].Range.Text = "Лицо, производящее переключение (ДЭМ/МГ):";
last.Rows[3].Cells[2].Range.Text = "_________/_____________________/";
last.Rows[4].Cells[1].Range.Text = "Лицо контролируюшее (НС):";
last.Rows[4].Cells[2].Range.Text = "_________/_____________________/";
last.Rows[2].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
last.Rows[3].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
last.Rows[4].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
last.Rows[2].Cells[2].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
//.........这里部分代码省略.........
示例8: replaceSpaces
protected void replaceSpaces(Document doc)
{
int count=0;
doc.Range().Find.Execute(FindText: "^w", MatchCase: false, ReplaceWith: " ", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "^w.", MatchCase: false, ReplaceWith: ".", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "^w^p", MatchCase: false, ReplaceWith: "^p", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "^p^w", MatchCase: false, ReplaceWith: "^p", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "–", MatchCase: false, ReplaceWith: "-", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: " -", MatchCase: false, ReplaceWith: "-", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "- ", MatchCase: false, ReplaceWith: "-", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "-", MatchCase: false, ReplaceWith: "–", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "« ", MatchCase: false, ReplaceWith: "«", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: " »", MatchCase: false, ReplaceWith: "»", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: " ГЭС– ", MatchCase: false, ReplaceWith: " ГЭС –~", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "–~", MatchCase: false, ReplaceWith: "– ", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "–110 кВ", MatchCase: false, ReplaceWith: " 110", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "–220 кВ", MatchCase: false, ReplaceWith: " 220", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "–500 кВ", MatchCase: false, ReplaceWith: " 500", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "–13,8 кВ", MatchCase: false, ReplaceWith: " 13,8", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "–110", MatchCase: false, ReplaceWith: " 110", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "–220", MatchCase: false, ReplaceWith: " 220", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "–500", MatchCase: false, ReplaceWith: " 500", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "–13,8", MatchCase: false, ReplaceWith: " 13,8", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "Иж–", MatchCase: false, ReplaceWith: "Ижевск ", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "Иж ", MatchCase: false, ReplaceWith: "Ижевск ", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "Ижевск–", MatchCase: false, ReplaceWith: "Ижевск ", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "Водозабор–", MatchCase: false, ReplaceWith: "Водозабор ", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "Каучук–", MatchCase: false, ReplaceWith: "Каучук ", Replace: WdReplace.wdReplaceAll);
doc.Range().Find.Execute(FindText: "КШТ–", MatchCase: false, ReplaceWith: "КШТ ", Replace: WdReplace.wdReplaceAll);
/*replaceVVL("КШТ 1", "110");
replaceVVL("КШТ 2", "110");
replaceVVL("Светлая", "110");
replaceVVL("Ивановка", "110");
replaceVVL("Каучук", "110");
//replaceVVL("Светлая", "110");
replaceVVL("ЧаТЭЦ", "110");
replaceVVL("Березовка", "110");
replaceVVL("Дубовая", "110");
replaceVVL("Водозабор 1", "110");
replaceVVL("Водозабор 2", "110");
replaceVVL("Карманово", "500");
replaceVVL("Емелино", "500");
replaceVVL("Вятка", "500");
replaceVVL("Ижевск 1", "220");
replaceVVL("Ижевск 2", "220");
replaceVVL("Каучук 1", "220");
replaceVVL("Каучук 2", "220");
//replaceVVL("Светлая", "220");*/
for (int i=0; i < 20; i++) {
doc.Range().Find.Execute(FindText: "^p^p", MatchCase: false, ReplaceWith: "^p", Replace: WdReplace.wdReplaceAll);
}
}
示例9: replaceNSGES
protected bool replaceNSGES(string fileName)
{
doc = app.Documents.Open(fileName, Visible: true, ReadOnly: false);
int count=0;
while (doc.Range().Find.Execute(FindText: "НС ГЭС", MatchCase: false, ReplaceWith: "НСС", Replace: WdReplace.wdReplaceOne)) {
count++;
}
Logger.log(fileName + "-" + count.ToString());
(doc as _Document).Close(SaveChanges: true);
return true;
}
示例10: makeSchema
protected void makeSchema(Document doc)
{
string schema=findTurn(doc);
if (schema.Length > 0) {
foreach (Paragraph p in doc.Range().Paragraphs) {
string text=p.Range.Text;
if (text.IndexOf("Исходная схема станции") == 0) {
Paragraph newP= doc.Paragraphs.Add(p.Next().Range);
newP.Range.Font.Bold = 0;
newP.Range.Font.Underline = 0;
newP.Range.Font.Italic = 1;
newP.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
newP.Range.Font.Size = 12;
newP.Range.Text = schema;
break;
}
}
}
}
示例11: findTurn
protected String findTurn(Document doc)
{
string[] onStrs={"Отключить ", "Проверить включенное положение "};
string[] offStrs= { "Включить ", "Проверить отключенное положение "};
List<String> resOn=new List<string>();
List<String> resOff=new List<string>();
foreach (Paragraph p in doc.Range().Paragraphs) {
string text=p.Range.Text;
foreach (string onStr in onStrs) {
if (text.IndexOf(onStr) >= 0) {
string obj=getObjectName(onStr, text);
if (obj.Length > 0) {
if (!resOff.Contains(obj) && !resOn.Contains(obj))
resOn.Add(obj);
}
}
}
foreach (string offStr in offStrs) {
if (text.IndexOf(offStr) >= 0) {
string obj=getObjectName(offStr, text);
if (obj.Length > 0) {
if (!resOn.Contains(obj) && !resOff.Contains(obj))
resOff.Add(obj);
}
}
}
}
string res="";
if (resOn.Count > 0 && resOff.Count > 0) {
res= "Включены: " + String.Join("; ", resOn.ToArray()) + "\nОтключены: " + String.Join("; ", resOff.ToArray()) + "\n";
}
return res;
}
示例12: createTipBlank
protected bool createTipBlank(string fileName, bool pdf, string pdfName)
{
doc = null;
try {
doc = app.Documents.Open(fileName, Visible: true, ReadOnly: false);
doc.Select();
doc.PageSetup.LeftMargin = 60;
doc.PageSetup.TopMargin = 30;
doc.PageSetup.BottomMargin = 30;
doc.PageSetup.RightMargin = 30;
doc.PageSetup.FooterDistance = 30;
doc.PageSetup.HeaderDistance = 0;
int x=doc.Range().Tables.Count;
Table first=doc.Range().Tables[1];
resetTable(first);
first.Range.Font.Size = 13;
first.Columns.Add();
first.AutoFormat(ApplyBorders: false, ApplyShading: false, ApplyFont: false, ApplyColor: false, ApplyHeadingRows: false,
ApplyLastRow: false, ApplyFirstColumn: false, AutoFit: true, ApplyLastColumn: false);
first.Rows[1].Cells[1].Range.Text = "Типовой бланк переключений \n№" + getNumber(fileName);
first.Rows[1].Cells[2].Range.Text = "Утверждаю\nГлавный инженер филиала\nОАО \"РусГидро\" - \"Воткинская ГЭС\"\n__________________Э.М. Скрипка\n\"____\"_____________2012г.";
first.AutoFitBehavior(WdAutoFitBehavior.wdAutoFitWindow);
Table last=doc.Range().Tables[doc.Range().Tables.Count];
resetTable(last);
last.Range.Font.Size = 12;
last.TopPadding = 20;
last.Columns.Add();
last.Columns.Add();
last.Rows.Add();
last.AutoFormat(ApplyBorders: false, ApplyShading: false, ApplyFont: false, ApplyColor: false, ApplyHeadingRows: false,
ApplyLastRow: false, ApplyFirstColumn: false, AutoFit: true, ApplyLastColumn: false);
last.Rows[1].Cells[1].Range.Text = "Начальник СТСУ";
last.Rows[1].Cells[2].Range.Text = "_____________________";
last.Rows[1].Cells[3].Range.Text = "Кочеев Н.Н.";
last.Rows[2].Cells[1].Range.Text = "Начальник ОС";
last.Rows[2].Cells[2].Range.Text = "_____________________";
last.Rows[2].Cells[3].Range.Text = "Иванов А.В.";
last.Rows[1].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
last.Rows[1].Cells[3].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
last.Rows[2].Cells[1].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
last.Rows[2].Cells[3].Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
last.AutoFitBehavior(WdAutoFitBehavior.wdAutoFitWindow);
//replaceSpaces(first);
//replaceSpaces(last);
replaceSpaces(doc);
//makeSchema(doc);
addFooter(fileName, doc, true);
podpis(doc, 7);
if (pdf) {
saveAsPDF(doc, pdfName);
}
Logger.log(fileName);
(doc as _Document).Close(SaveChanges: true);
return true;
} catch (Exception e) {
try { (doc as _Document).Close(SaveChanges: false); } catch { }
Logger.log("ERROR: " + fileName);
Logger.log("--" + e.Message);
return false;
}
}