Ejemplo n.º 1
0
        /// <summary>
        /// 將字典檔丟附openxmlmanager
        /// </summary>
        /// <param name="templateFilePath">template file path</param>
        /// <param name="textDict">text value pair dictionary</param>
        /// <param name="imageDict">image value pair dictionary</param>
        /// <param name="tableDict">table value pair dictionary</param>
        /// <returns>complete template docx file path</returns>
        public string DocxMaker(
            string templateFilePath,
            Dictionary <string, OpenXmlTextInfo> textDict = null,
            Dictionary <string, MemoryStream> imageDict   = null,
            Dictionary <string, Table> tableDict          = null)
        {
            string templateDocx = templateFilePath;
            string tempDocx     = Path.GetTempPath() + Guid.NewGuid() + ".docx";

            // copy the word doc so you can see the difference between the two
            File.Delete(tempDocx);
            File.Copy(templateDocx, tempDocx);

            var wordManager = new WordManager();

            wordManager.OpenDocuemnt(tempDocx);

            if (textDict != null && textDict.Any())
            {
                wordManager.UpdateText(textDict);
            }

            if (tableDict != null && tableDict.Any())
            {
                wordManager.UpdateTable(tableDict);
            }

            if (imageDict != null && imageDict.Any())
            {
                wordManager.UpdateImage(imageDict);
            }

            wordManager.CloseDocument();

            return(tempDocx);
        }