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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Word = Microsoft.Office.Interop.Word;
namespace formatage
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void CreateWordDocument(object fileName,
object saveAs)
{
//Set Missing Value parameter - used to represent
// a missing value when calling methods through
// interop.
object missing = System.Reflection.Missing.Value;
//Setup the Word.Application class.
Word.Application wordApp =
new Word.Application();
//Setup our Word.Document class we'll use.
Word.Document aDoc = null;
// Check to see that file exists
if (File.Exists((string)fileName))
{
DateTime today = DateTime.Now;
object readOnly = false;
object isVisible = false;
//Set Word to be not visible.
wordApp.Visible = false;
//Open the word document
aDoc = wordApp.Documents.Open(ref fileName, ref missing,
ref readOnly, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref isVisible, ref missing, ref missing,
ref missing, ref missing);
// Activate the document
aDoc.Activate();
double amount = 1256898.1625;
//formatage de "amount"
}
else
{
MessageBox.Show("File dose not exist.");
return;
}
//Save the document as the correct file name.
aDoc.SaveAs(ref saveAs, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing);
//Close the document - you have to do this.
aDoc.Close(ref missing, ref missing, ref missing);
MessageBox.Show("File created.");
}
//Ensuite, j'appelle ci-dessus:
private void button1_Click(object sender, EventArgs e)
{
CreateWordDocument(@"C:\temp\AvantFormatage.doc",
@"C:\temp\ResultatFormatage.doc");
}
}
} |
Partager