Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   .NET-Sprachen (https://www.delphipraxis.net/82-net-sprachen/)
-   -   C# Text bei Textmarke einfügen (https://www.delphipraxis.net/162597-text-bei-textmarke-einfuegen.html)

API 30. Aug 2011 19:29

Text bei Textmarke einfügen
 
Hallo,

Habe vor kurzem angefangen C# zu lernen und möchte diesen Delphi Code nach C# zu übersetzen. Habe schon viel gegoogelt, jedoch ehere komplizierten Code gefunden.

Kann mir jemand beim Übersetzen helfen?

Delphi-Quellcode:
    WordApp := CreateOleObject('Word.Application'); // mit late binding
    WordApp.Documents.Open("C:\....docx");
    Doc := WordApp.ActiveDocument;

  BookmarkName := 'Meine_Textmarke';
  if Doc.Bookmarks.Exists(BookmarkName) then
  begin
    R := Doc.Bookmarks.Item(BookmarkName).Range;
    R.InsertAfter('Text....');
  end;

API 1. Sep 2011 16:58

AW: Text bei Textmarke einfügen
 
push :x

API 7. Sep 2011 10:35

AW: Text bei Textmarke einfügen
 
...oder kann jemand behilflich sein beim Übersetzen dieses VBA Codes nach C#?

Code:
Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
    Dim BMRange As Range
    Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
    BMRange.Text = TextToUse
    ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub
(oder jemand ein C# Forum empfehlen?)

Phoenix 7. Sep 2011 10:40

AW: Text bei Textmarke einfügen
 
Zitat:

Zitat von API (Beitrag 1122368)
...oder kann jemand behilflich sein beim Übersetzen dieses VBA Codes nach C#?

Code:
Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As String)
    Dim BMRange As Range
    Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
    BMRange.Text = TextToUse
    ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub
(oder jemand ein C# Forum empfehlen?)

Code:
void UpdateBookmark(string bookmarkToUpdate, string textToUse)
{
  var range = ActiveDocument.Bookmarks(BookmarkToUpdate).Range;
  range.Text = textToUse;
  ActiveDocument.Bookmarks.Add(bookmarkToUpdate, range);
}

API 13. Sep 2011 19:12

AW: Text bei Textmarke einfügen
 
Code:
var range
ist doch nicht C# :?

Dawn87 13. Sep 2011 19:16

AW: Text bei Textmarke einfügen
 
Doch ist es. Das var-Schlüsselwort kann ersatzweise für den Datentyp verwendet werden, wenn durch die darauf folgende Zuweisung klar ist um welchen Datentyp bzw. um welche Klasse es sich handelt.

Ist erst ab C# 3.0 verfügbar:
http://msdn.microsoft.com/en-us/library/bb383973.aspx


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:35 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz