Я вставил его в текстовый документ и текстовое поле (элемент ActiveX). Я хотел бы получить доступ к этому элементу управления, например, изменив содержимое текста. Я попробовал следующий код, но он не работает.using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using Microsoft.Vbe.Interop.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.Application alex = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document alexdoc = new Microsoft.Office.Interop.Word.Document();
alexdoc = null;
try
{
alexdoc = alex.Documents.Open(@"C:\Users\Alex\Documents\doc1.docx");
alex.Visible = false;
foreach (Shape shape in alexdoc.Shapes)
{
if (shape.OLEFormat != null && shape.OLEFormat is Microsoft.Vbe.Interop.Forms.TextBox)
{
var nome = (Microsoft.Vbe.Interop.Forms.TextBox)shape.OLEFormat.Object;
nome.Text = "alex";
var TextBox1 = (Microsoft.Vbe.Interop.Forms.TextBox)shape.OLEFormat.Object;
TextBox1.Text = "riuscito";
}
MessageBox.Show(shape.Name);
}
alexdoc.SaveAs2(@"C:\Users\Alex\Documents\alexmodificato.docx");
}
catch (System.Exception ex)
{
label1.Text = "errore" + ex.Message;
}
finally
{
alexdoc?.Close(false);
alex.Quit();
alexdoc = null;
alex = null;
}
}
}
}
Надеюсь, вы поможете мне с кодом или подскажете, где найти документацию
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using Microsoft.Vbe.Interop.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.Application alex = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document alexdoc = new Microsoft.Office.Interop.Word.Document();
alexdoc = null;
try
{
alexdoc = alex.Documents.Open(@"C:\Users\Alex\Documents\doc1.docx");
alex.Visible = false;
foreach (Shape shape in alexdoc.Shapes)
{
if (shape.OLEFormat != null && shape.OLEFormat is Microsoft.Vbe.Interop.Forms.TextBox)
{
var nome = (Microsoft.Vbe.Interop.Forms.TextBox)shape.OLEFormat.Object;
nome.Text = "alex";
var TextBox1 = (Microsoft.Vbe.Interop.Forms.TextBox)shape.OLEFormat.Object;
TextBox1.Text = "riuscito";
}
MessageBox.Show(shape.Name);
}
alexdoc.SaveAs2(@"C:\Users\Alex\Documents\alexmodificato.docx");
}
catch (System.Exception ex)
{
label1.Text = "errore" + ex.Message;
}
finally
{
alexdoc?.Close(false);
alex.Quit();
alexdoc = null;
alex = null;
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... tents-word
Редактировать содержимое текстового поля слово ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как перенести слово на предыдущее слово, если не подходит только последнее слово
Anonymous » » в форуме Android - 0 Ответы
- 133 Просмотры
-
Последнее сообщение Anonymous
-