This article introduces the basis of word Template export word Method of documentation .

One 、 Get template address

 WordDocFileHelper WordTem = new WordDocFileHelper();
string path = @"TempleteWord\ReportRepair.dotx";
string fullName = System.Windows.Forms.Application.StartupPath.Substring(, System.Windows.Forms.Application.StartupPath.LastIndexOf("\\"));
fullName = fullName.Substring(, fullName.LastIndexOf("\\")) + "\\" + path;

Two 、 Create a new document from a template

 WordTem.CreateNewDocument1(fullName);
 public void CreateNewDocument1(string filePath)
{
wordApp = new ApplicationClass();// Create a word Application instance
wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone;
wordApp.Visible = false;// Set to invisible
object missing = System.Reflection.Missing.Value;
object format = WdSaveFormat.wdFormatDocument;
object templateName = filePath;// Template file address
wordDoc = wordApp.Documents.Add(ref templateName, ref missing,ref missing, ref missing);
}

3、 ... and 、 Insert value at template bookmark

WordTem.InsertValue("XMMC", ID);
 public bool InsertValue(string bookmark, string value)
{
object bkObj = bookmark;
if (wordApp.ActiveDocument.Bookmarks.Exists(bookmark))
{
wordApp.ActiveDocument.Bookmarks.get_Item(ref bkObj).Select();
wordApp.Selection.TypeText(value);
return true;
}
return false;
}

Four 、 Choose a save location

 FolderBrowserDialog path = new FolderBrowserDialog();
path.Description = " Select the folder you want to save ";
path.ShowDialog();
SaveFilePath = path.SelectedPath;

5、 ... and 、 Save documents automatically

WordTem.SaveDocument(SaveFilePath + "\\" + name + ".doc");
 public void SaveDocument(string Filename)
{
object fileName = Filename;
object format = WdSaveFormat.wdFormatDocument;// Save format
object miss = System.Reflection.Missing.Value;
wordDoc.SaveAs(ref fileName, ref format, ref miss,
ref miss, ref miss, ref miss, ref miss,
ref miss, ref miss, ref miss, ref miss,
ref miss, ref miss, ref miss, ref miss,
ref miss);
// close wordDoc,wordApp object
object SaveChanges = WdSaveOptions.wdSaveChanges;
object OriginalFormat = WdOriginalFormat.wdOriginalDocumentFormat;
object RouteDocument = false;
wordDoc.Close(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
wordApp.Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
}

6、 ... and 、 Replace with word Middle selection box

 public string ReplaceCheckCell(string text)
{
wordApp.Selection.Find.Replacement.Font.Name = "Wingdings 2";
// Set the font type here .Wingdings 2 Under the font \u0052 The selection box for tick ,\u00A3 Represents the unchecked selection box
string Normal = "\u0052 normal \u00A3 Is not normal ";
string UnNormal = "\u00A3 normal \u0052 Is not normal ";
if (text == " normal ")
{
wordApp.Selection.Find.Replacement.Text = Normal;
return Normal;
}
else if (text == " Is not normal ")
{
wordApp.Selection.Find.Replacement.Text = UnNormal;
return UnNormal;
}
else { return ""; }
}

7、 ... and 、 When exporting, you need to open the file by default , It is saved by the user himself

 public void CreateNewDocument0(string filePath, string filename)
{
//killWinWordProcess();
wordApp = new ApplicationClass();// Create a word Application instance
wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone;
wordApp.Visible = false;// Set to invisible
object missing = System.Reflection.Missing.Value;
object format = WdSaveFormat.wdFormatDocument;
object fileName = filename;
object templateName = filePath;// Template file address
wordDoc = wordApp.Documents.Open(ref templateName, 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); // Save the document
wordDoc.SaveAs(ref fileName, ref format, 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);
}
 public void OpenDocument(string Filename)
{
object fileName = Filename;
object Missing = System.Reflection.Missing.Value;
object readOnly = true;
wordDoc = 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 Missing, ref Missing, ref Missing, ref Missing, ref Missing);
////wordApp.Visible = true;
////wordDoc.PrintPreview();// Print preview
}

Data export winfrom export word( Two ) More articles about

  1. Data export winfrom export word( One )

    We often use winfrom Program development tools , Use dataGridView Control to display data . meanwhile , We will also have the need to export these data . This article introduces the problems encountered in the development process . One . Refer to the component First , Need to refer to in the form program ...

  2. Java Realization PDF and Excel Generation and data dynamic insertion and export

    One . preface Excel.PDF Export of . Import is a common problem in our work , Just today, the company's business encountered this problem , By the way, take a note in case you're stuck with the same problem next time . The company has two needs : Need one . Given a form , Let's ...

  3. asp.net course :GridView Export to Excel or Word file

    asp.net course :GridView Export to Excel or Word file </ br> In projects, we often encounter the requirement to export some data to Excel perhaps Word The situation of the form , For example, China Mobile ( I'm a Chinese mobile user ) ...

  4. asp.net take word Edit the document and export a new word

    Recent projects , Need more word Edit the document and export a new word, In the initial word Leave a specific string in the edit to replace , And then generate a new one locally word file , And don't modify the word file , In order to ensure that the server ...

  5. be based on Metronic Of Bootstrap Experience summary of development framework (7)-- Data import 、 Export and attachment processing

    In many system modules , We may all need to do some data exchange , That is, data import or export operation , Such batch processing can give system users a better operation experience , It also improves the efficiency of data entry . I was in an earlier period of EasyUI Of Web On the frame , ...

  6. C# It becomes data import Excel And export Excel

    excel  Basics • Whole excel  Forms are called worksheets :workbook: A worksheet contains pages :sheet: That's ok :row: Cell :cell. •excel  The phone number problem in , A string that looks like a number begins with a half angle single quotation mark ...

  7. Ireport Report export Poi + ireport export pdf, word ,excel ,htm

    Ireport  Report export  Poi + ireport  export pdf, doc ,excel ,html  Format The following is the report export tool class reportExportUtils  You need to export the report in the above format   Just call this ...

  8. Oracle Data import and export (SID service.msc)

    One : Version number Description : (1)(Oracle11  32 Bit system )Oracle - OraDb11g_home1: (2) The demo sample after successful installation is as follows : The first one is management tools . Create connection . Create table : The second is the database builder ...

  9. freemarker Export... With pictures word file

    Recently do a document export function , By the way, I learned freemarker, Made a picture on the export of word file , The template is not complete , Just to verify the correctness of the code It's just a little function , So only do the background code about the export code , Not with the front desk ...

Random recommendation

  1. stay MySQL When inserting Chinese into a table , appear :incorrect string value error

    stay MySQL When inserting Chinese into a table , appear :incorrect string value  error , Because the character set does not support Chinese . The solution is to change the character set to GBK, or UTF-8.       One . Modify the default character set of the database   ...

  2. Java( Two )

    after class , I look up relevant study materials and Java API We made the following interface , The interface contains radio buttons (JRadioButton). Check box (JCheckBox). Combo box (JComboBox). Single line text input box (JTextFiel ...

  3. HTTP Analysis of the principle of long connection and short connection

    Original text :HTTP Analysis of the principle of long connection and short connection

  4. discuz To build

    This article will introduce IIS+MySQL+DiscuzX3.1+UCenter1.6+Asp.Net+PHP Deployment of Most of them were transported , Of course, I will indicate the place of transportation build First, the basic information of this machine is explained System ========== ...

  5. day-8

    /* Reciprocal 8 days Apply for the college entrance examination today The two head teachers are here 23333 Then fill in the head teacher's name is embarrassed 23333 The morning exam That's a good topic It's not very water But it takes thinking And I am a face of ignorant force ~~ Organize all kinds of boards in the afternoon It's mainly graph theory most ...

  6. Java The concept of modularity and summary of the current situation

    In the past few years ,Java Modularity has always been an active topic . from JSR 277( It has been abolished ) To JSR 291, Modularity looks like Java There is a necessary link in the process of evolution . Even based on JVM The language of the future , such as Scala, Also consider the modular question ...

  7. How to remove List The repetition value in ?

    There is a problem today , There is already one List<string>, There are duplicate values in it , I want to get rid of the duplicate values , At the same time, you can't break the existing order . thank http://bbs.csdn.net/topics/39024721 ...

  8. Alamofire Source code interpretation series ( Ten ) Serialization (ResponseSerialization)

    This article mainly explains Alamofire How to serialize the data returned by the server in Preface Different from the previous article , In this article , I want to interpret it from the design level of the program ResponseSerialization This file . A more intuitive way to explore this function is ...

  9. Web front end : Blog beautification : 3、 ... and 、 In the top right corner of the Github Ribbon

    1. Save the pictures to the blog album 2. Copy the code so that you can put html Where to code Because of the quantity, I put this paragraph sei here we are The first page Html Code <a href="https://github.com/zhengw ...

  10. Docker: Use customization redis.conf function redis Containers (7)

    Demo environment :win7+docker toolbox 1. Custom configuration files First, in the Windows Prepare the configuration file in the environment redis Then open the Quickstart Terminal input command : cp -rf ~/Desktop/ ...