Announcement

Collapse
No announcement yet.

Brauch driiiingend Hilfe in Word

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Brauch driiiingend Hilfe in Word

    Hallo Leute.
    Ich hab ein Tool programmiert das ein Form öffnet in dem ein Button ist, der ein Worddokument öffnet. Danach wird die Sprechdauer des Textes berechnet und in das Dokument sowie in das Form (textbox) geschrieben. Mein Problem ist jetzt das diese Sprechzeit aktualisiert werden soll wenn sich der Text in dem Dokument ändert. Ich hab eigentlich nur 2 Möglichkeiten:
    1. Die Zeit wird irgendwie in dem Form aktualisiert oder
    2. Über ein Addin wird in Word eine textbox in der Menueleiste erzeugt welche ständig aktualisiert wird.

    Ich bin leider ziehmlich neu in der OOP und hab bis jetzt nur reines uController C programmiert. Wenn mir jemand Tips geben könnte wäre das echt Klasse.
    Hab mal nen Teil meines Codes beigefügt

    /************************************************** ***************/
    /******Aktion für Button 1***************************************/
    /************************************************** ***************/
    private void Button1_Clicked(object sender, EventArgs e)
    {
    double Sprechconst = 0.07; //Sprechdauer für ein Zeichen

    // Zeigt den Datei öffnen Dialog an
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.InitialDirectory = "c:\\" ;
    openFileDialog1.Filter = "Dokument Dateien(*.doc)|*.doc|Alle Dateien (*.*)|*.*" ;
    openFileDialog1.FilterIndex = 2 ;
    openFileDialog1.Title = "Dokumentdatei auswählen";

    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
    object fileName = openFileDialog1.FileName.ToString();
    Microsoft.Office.Interop.Word.Application word = null;
    Microsoft.Office.Interop.Word.Document doc = null;
    word = new Microsoft.Office.Interop.Word.Application();
    word.Visible = true;
    object readOnly = false; //Dokument schreibgeschützt ja/nein
    object optional = Type.Missing;
    word.Activate();
    doc = word.Documents.Open(ref fileName, ref optional, ref readOnly, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional);
    doc.Activate();

    //Zeichen Zählen und Sprechdauer ausgeben
    object footnote=false;
    //string sZeichen = doc.ComputeStatistics(Microsoft.Office.Interop.Wor d.WdStatistic.wdStatisticCharactersWithSpaces, ref footnote).ToString();
    double dWortlänge = doc.ComputeStatistics(Microsoft.Office.Interop.Wor d.WdStatistic.wdStatisticCharactersWithSpaces, ref footnote)*(Sprechconst);
    string sWoerter = doc.ComputeStatistics(Microsoft.Office.Interop.Wor d.WdStatistic.wdStatisticWords,ref footnote).ToString();
    //doc.Words.Last.InsertAfter("\nSprechzeit: \t" + dWortlänge + "Sekunden ("+ sWoerter+"Wörter)" );
    string sWortlänge = dWortlänge.ToString();
    textBox1.Text = "Sprechzeit: " +sWortlänge +"s";

    }

    }

    /************************************************** ***************/
    /******Aktion für Button 2***************************************/
    /************************************************** ***************/
    private void Button2_Clicked(object sender, EventArgs e)
    {
    double Sprechkonstante = 0.07; //Sprechdauer eines Zeichens

    Microsoft.Office.Interop.Word.Application word = null;
    Microsoft.Office.Interop.Word.Document doc = null;
    word = new Microsoft.Office.Interop.Word.Application();
    word.Visible = true;

    object optional = Type.Missing;
    word.Activate();

    /***Neues Dokument erzeugen*/
    doc = word.Documents.Add(ref optional, ref optional,ref optional,ref optional);
    doc.Activate();
    doc.Words.First.InsertBefore("Embedded World");
    object TitelEnde=doc.Characters.Count;
    doc.Words.Last.InsertAfter ("\n\r\rErstellt von: \tAlexander Ditte");
    doc.Words.Last.InsertAfter ("\nDatum: \t\n");
    doc.Words.Last.InsertDateTime(ref optional,ref optional,ref optional,ref optional,ref optional);

    /*********************************************/
    /****Zeichen zählen und Textlänge ausgeben****/
    /*********************************************/
    object footnote=false;
    //string sZeichen = doc.ComputeStatistics(Microsoft.Office.Interop.Wor d.WdStatistic.wdStatisticCharactersWithSpaces, ref footnote).ToString();
    //double dWortlänge = doc.ComputeStatistics(Microsoft.Office.Interop.Wor d.WdStatistic.wdStatisticCharactersWithSpaces, ref footnote)*(Sprechkonstante);
    //string sWoerter = doc.ComputeStatistics(Microsoft.Office.Interop.Wor d.WdStatistic.wdStatisticWords,ref footnote).ToString();
    //doc.Words.Last.InsertAfter("Sprechzeit: \t" + dWortlänge + "Sekunden ("+ sWoerter+"Wörter)" );



    /**************************************/
    /****Text markieren und formatieren****/
    /**************************************/
    object first=0;
    //doc.Range(ref first, ref last).Select(); //Selektion anzeigen
    doc.Range(ref first, ref TitelEnde).Font.Size = 20;
    doc.Range(ref first, ref TitelEnde).ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment .wdAlignParagraphCenter;

    double dWortlänge = doc.ComputeStatistics(Microsoft.Office.Interop.Wor d.WdStatistic.wdStatisticCharactersWithSpaces, ref footnote)*(Sprechkonstante);
    string sWortlänge = dWortlänge.ToString();
    textBox1.Text = "Sprechzeit: " +sWortlänge +"s";


    }
Working...
X