1 / 1 / 0
Регистрация: 26.12.2010
Сообщений: 65
1

Чтение и запись в doc\docx файл

26.05.2012, 15:29. Показов 19242. Ответов 5
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
искал на форуме и в гугле и так не нашёл нормальной статьи как считать данные из файла doc\docx и записать тоже.
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
26.05.2012, 15:29
Ответы с готовыми решениями:

Чтение, редактирование и запись в .doc файл
у меня совсем небольшой опыт программирования, поэтому прошу помощи... нужно открыть .doc файл,...

Открытие и чтение файлов .doc/.docx
помогите. как средствами visual studio на C# открыть файлы .doc/.docx и прочитать все содержимое...

Чтение doc/docx без использования MS Office
Здравствуйте. Подскажите пожалуйста, есть ли какие-нибудь бесплатные компоненты для чтения файлов...

Чтение и запись *.doc,*.docx на диск
Всем привет!! У Лафоре очень хорошо объяснено и показано запись и считывание файлов с диска с...

5
118 / 118 / 25
Регистрация: 03.03.2010
Сообщений: 436
26.05.2012, 15:53 2
Открытие и чтение файлов .doc/.docx
1
1 / 1 / 0
Регистрация: 26.12.2010
Сообщений: 65
27.05.2012, 17:26  [ТС] 3
Я сделал программу, но конечный файл и исходный отличаются тем что конечный полностью без форматирования, как это поправить?
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core; 
 
namespace WindowsFormsApplication1
{
    class RabWord
    {
        public String OpenWord(Object filename)
        {
            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;
            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);
            Word.Document Doc = new Microsoft.Office.Interop.Word.Document();
            Doc = Progr.Documents.Application.ActiveDocument;
            object start = 0;
            object stop = Doc.Characters.Count;
            Word.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;
        }
   
    }
}
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using System.Reflection;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
 
        public Form1()
        {
            InitializeComponent();
        }
 
 
        private void button1_Click(object sender, EventArgs e)
        {
            Object filename="";
            RabWord a = new RabWord();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                 filename=openFileDialog1.FileName;
             
            string Text=a.OpenWord(filename);
 
            Text = Text.Replace("{number_docs}", textBox1.Text);
            Text = Text.Replace("{data_rogdenia}", textBox2.Text);
            Text = Text.Replace("{pasporTOO}", textBox3.Text);
            Text = Text.Replace("{money}", textBox4.Text);
            Text = Text.Replace("{data_razvrata}", textBox5.Text);
            Text = Text.Replace("{feo_zaem}", textBox6.Text);
            Text = Text.Replace("{serea_pasport}", textBox7.Text);
            Text = Text.Replace("{serea_number}", textBox8.Text);
            Text = Text.Replace("{vedan_pasport}", textBox9.Text);
            Text = Text.Replace("{adress_reg}", textBox10.Text);
            Text = Text.Replace("{fio_menedgera}", textBox11.Text); 
 
 
 
 
 
 
 
            object oMissing = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
 
            //Start Word and create a new document.
            Word._Application oWord;
            Word._Document oDoc;
            oWord = new Word.Application();
            oWord.Visible = true;
            oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
                ref oMissing, ref oMissing);
 
            //Insert a paragraph at the beginning of the document.
            Word.Paragraph oPara1;
            oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);
            oPara1.Range.Text = Text;
            oPara1.Range.Font.Bold = 1;
            oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.
            oPara1.Range.InsertParagraphAfter();         
 
            //Close this form.
            this.Close();
            
            }    
        }
 
 
    }
}
1
1 / 1 / 0
Регистрация: 26.12.2010
Сообщений: 65
30.05.2012, 09:57  [ТС] 4
Вверх
0
Эксперт Java
4090 / 3824 / 745
Регистрация: 18.05.2010
Сообщений: 9,331
Записей в блоге: 11
30.05.2012, 11:21 5
У Documents.Add есть параметры, позволяющие указать шаблон для нового документа.
C#
1
oDoc = oWord.Documents.Add(filename/*Имя шаблона*/, false, Missing.Value, true);
0
33 / 32 / 7
Регистрация: 13.12.2010
Сообщений: 342
02.02.2013, 23:42 6
А как используя код выше сделать следующее:
1) прочитать текст (это понятно)
2) редактировать его - "найти и заменить" - тоже ничего сложного, использовать .Replace()
3) записать отредактированный текст обратно в файл?
0
02.02.2013, 23:42
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
02.02.2013, 23:42
Помогаю со студенческими работами здесь

Создание/склеивание doc\docx файла из шаблона doc\docx с заменой ключевых слов
Подскажите, как можно такое реализовать? Я узнал, что в rtf нельзя делать разрыв страницы, а...

Запись и чтение в doc-файл
Подскажите, пожалуйста, как произвести запись/чтение файл.doc

Чтение *.doc и *.docx
Здравствуйте. Помогите пожалуйста решить проблему: как прочитать *.doc и *.docx файлы в wpf...

Чтение docx и doc
Здравствуйте. Скажите пожалуйста, как считать доковские документы ? И как их перевести в случае...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
6
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2023, CyberForum.ru