コード例 #1
0
ファイル: IntegrationService.cs プロジェクト: leonchen09/poc
        public UserData GetLastSelectedDomain()
        {
            try
            {
                string data = FileAdapter.ReadUserData();

                UserData userData = string.IsNullOrWhiteSpace(data) ? null :
                                    ObjectSerializeHelper.Deserialize <UserData>(data);

                return(userData);
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_LoadResourceError);
                newSrvExp.Errors.Add(srvExp);

                throw newSrvExp;
            }
            catch (Exception ex)
            {
                ServiceException srvExp = new ServiceException(Core.ErrorCode.ipe_LoadResourceError,
                                                               Core.MessageUtils.Expand(Properties.Resources.ipe_LoadResourceError, ex.Message), ex.StackTrace);
                throw srvExp;
            }
        }
コード例 #2
0
 public void TestXml(int i)
 {
     if (i == 1)
     {
         ObjTest t = new ObjTest();
         t.age      = 10;
         t.name     = "张三";
         t.birthday = DateTime.Now;
         t.sex      = false;
         string       xmlContent = ObjectSerializeHelper.SerializeToString <ObjTest>(t);
         FileStream   fout       = new FileStream("e:\\1.xml", FileMode.Create);
         StreamWriter sw         = new StreamWriter(fout);
         sw.Write(xmlContent);
         sw.Close();
         fout.Close();
     }
     else
     {
         StreamReader objReader  = new StreamReader("e:\\1.xml");
         string       sLine      = "";
         string       xmlcontent = "";
         while (sLine != null)
         {
             sLine = objReader.ReadLine();
             if (sLine != null && !sLine.Equals(""))
             {
                 xmlcontent += sLine;
             }
         }
         objReader.Close();
         MapNode mn = ObjectSerializeHelper.Deserialize <MapNode>(xmlcontent);
     }
 }
コード例 #3
0
        public bool SaveExportInfo(Workbook workbook)
        {
            //clear old export item information xml
            foreach (CustomXMLPart curXmlPart in workbook.CustomXMLParts)
            {
                if (curXmlPart.BuiltIn)
                {
                    continue;
                }
                XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(curXmlPart.XML);
                if (customObject.ContentType == ContentType.PdeExportItem)
                {
                    curXmlPart.Delete();
                    break;
                }
            }
            //add new information
            CustomXMLPart xmlPart      = workbook.CustomXMLParts.Add();
            string        xmlContent   = ObjectSerializeHelper.SerializeToString <PdeExports>(new PdeExports(exportItems));
            XmlObject     excelContent = new XmlObject(xmlContent, ContentType.PdeExportItem);

            xmlPart.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(excelContent));

            return(true);
        }
コード例 #4
0
        public bool SaveMapInfo(Workbook workbook)
        {
            //clear old map information xml
            foreach (CustomXMLPart curXmlPart in workbook.CustomXMLParts)
            {
                if (curXmlPart.BuiltIn)
                {
                    continue;
                }
                XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(curXmlPart.XML);
                if (customObject.ContentType == ContentType.PdeMapInfo)
                {
                    curXmlPart.Delete();
                    break;
                }
            }
            //add new map information
            CustomXMLPart xmlPart      = workbook.CustomXMLParts.Add();
            string        xmlContent   = ObjectSerializeHelper.SerializeToString <MapInfo>(mapInfo);
            XmlObject     excelContent = new XmlObject(xmlContent, ContentType.PdeMapInfo);

            xmlPart.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(excelContent));

            //Generate new xsd file and import it.
            GenXsd genXsd = new GenXsd();

            prepareData(genXsd);
            XmlMap xmap = genXsd.ImportXsd(workbook);

            //add xpath for each mapped cell and table
            foreach (MapNode mn in mapInfo.Maps)
            {
                if (mn.type == MapType.SingleCell)
                {
                    Range c = workbook.Application.get_Range(mn.target);
                    c.XPath.SetValue(xmap, mn.xPath);
                }
                else
                {
                    string[]   target    = mn.target.Split('!');
                    Worksheet  worksheet = workbook.Sheets[target[0]];
                    ListObject lst       = worksheet.ListObjects[target[1]];
                    foreach (TabCol tc in mn.columns)
                    {
                        lst.ListColumns[tc.columnName].XPath.SetValue(xmap, tc.xPath);
                    }
                }
            }

            return(true);
        }
コード例 #5
0
ファイル: IntegrationService.cs プロジェクト: leonchen09/poc
        public ChecksumInfo GetChecksum()
        {
            try
            {
                string          srvKey = string.Empty;
                ServicesProfile srvPro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out srvKey);
                GetPdwInformation(srvKey);
                Wkl.MainCtrl.ServiceCtrl.RemoveDataObject(srvKey);
                List <XmlObject> customXmls = srvPro.XmlObjects;
                ChecksumInfo     checksum   = null;
                string           osql       = string.Empty;

                foreach (XmlObject xmlObject in customXmls)
                {
                    if (xmlObject == null)
                    {
                        continue;
                    }

                    if (xmlObject.ContentType == ContentType.Checksum)
                    {
                        checksum = ObjectSerializeHelper.Deserialize <ChecksumInfo>(xmlObject.Content);
                        checksum.InternalBookmark = GetInternalBookmarkString();
                        checksum.Osql             = osql;
                    }
                    else if (xmlObject.ContentType == ContentType.Osql)
                    {
                        osql = xmlObject.Content;
                        if (checksum != null)
                        {
                            checksum.Osql = osql;
                        }
                    }
                }

                return(checksum != null ? checksum : new ChecksumInfo());
            }
            catch (BaseException srvExp)
            {
                Services.ServiceException newSrvExp = new Services.ServiceException(ErrorCode.ipe_GetChecksumError);
                newSrvExp.Errors.Add(srvExp);

                throw newSrvExp;
            }
            catch (Exception ex)
            {
                ServiceException srvExp = new ServiceException(ErrorCode.ipe_GetChecksumError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_GetChecksumError, ex.Message), ex.StackTrace);
                throw srvExp;
            }
        }
コード例 #6
0
ファイル: ThisAddIn.cs プロジェクト: leonchen09/poc
        private void unZipExcelFile(string tempFolder, Dictionary <string, string> oldFileNames, Dictionary <string, string> newFileNames)
        {
            string[] customeXmlFiles = Directory.GetFileSystemEntries(tempFolder + "\\customXml\\", "*.xml");
            Regex    custXmlRegex    = new Regex(@"item\d*.xml");//we need item*.xml only, do not need imemProps*.xml.

            foreach (string custXmlFile in customeXmlFiles)
            {
                if (custXmlRegex.IsMatch(custXmlFile))
                {
                    StreamReader sr      = new StreamReader(custXmlFile);
                    string       content = sr.ReadToEnd();
                    sr.Close();
                    sr = null;
                    XmlObject custXml = ObjectSerializeHelper.Deserialize <XmlObject>(content);
                    if (custXml.ContentType == ContentType.ImportedPde)
                    {
                        PdeContent pdeImported      = ObjectSerializeHelper.Deserialize <PdeContent>(custXml.Content);
                        string     importedFileName = pdeImported.FullFileName;
                        string     oldFileName      = null;
                        string     newFileName      = null;
                        //get new excel file name which has been updated into the document.
                        Dictionary <string, string> .Enumerator em = oldFileNames.GetEnumerator();
                        while (em.MoveNext())
                        {
                            oldFileName = null;
                            newFileName = null;
                            oldFileName = em.Current.Value;
                            if (pdeImported.FullFileName.Equals(oldFileName))
                            {
                                newFileNames.TryGetValue(em.Current.Key, out newFileName);
                                break;
                            }
                        }
                        FileHelper.ExcelFromBase64(pdeImported.FileContent, newFileName);

                        //replace file name with new name.
                        //content = content.Replace(oldFileName, newFileName);
                        //StreamWriter sw = new StreamWriter(custXmlFile);
                        //sw.Write(content);
                        //sw.Close();
                        //sw = null;
                        pdeImported.FullFileName = newFileName;
                        custXml.Content          = ObjectSerializeHelper.SerializeToString <PdeContent>(pdeImported);
                        content = ObjectSerializeHelper.SerializeToString <XmlObject>(custXml);
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(content);
                        xmlDoc.Save(custXmlFile);
                    }
                }
            }
        }
コード例 #7
0
ファイル: IntegrationManager.cs プロジェクト: leonchen09/poc
        private PdeContent GetPdeContent()
        {
            string pdeContentId = GetPropertyValue(PdwInfo.PdeContentXmlPartId);

            if (pdeContentId == null)
            {
                return(null);
            }

            string     pdeContentData = GetCustomXmlPartContent(pdeContentId);
            XmlObject  xmlObject      = ObjectSerializeHelper.Deserialize <XmlObject>(pdeContentData);
            PdeContent pdeContent     = ObjectSerializeHelper.Deserialize <PdeContent>(xmlObject.Content);

            return(pdeContent);
        }
コード例 #8
0
        private void BuildRender()
        {
            string msg = string.Empty;

            try
            {
                string mdbStr = txtMDB.Text;
                MDB    mdb    = new MDB();
                RenderArgumentValue renderArgValue = new RenderArgumentValue();

                try
                {
                    mdb = ObjectSerializeHelper.Deserialize <MDB>(mdbStr);
                }
                catch (Exception)
                { msg += "Format invalid: MDB !!!"; }


                string renderArgumentValue = txtRenderArgDomain.Text;
                try
                {
                    renderArgValue = ObjectSerializeHelper.Deserialize <RenderArgumentValue>(renderArgumentValue);
                }
                catch (Exception)
                { msg += "Format invalid: SXRenderArgumentValue !!!"; }

                //Get Osql data from db
                PreviewBiz previewBiz = new PreviewBiz();

                List <ChecksumInfoItem>     lstCheckSumItems = this.CheckSumInfo.ChecksumInfoItems;
                Dictionary <string, string> dicOsqlXml       = previewBiz.GetOsqlDataFromAppDB(lstCheckSumItems, renderArgValue, mdb, this.OsqlXml, ref msg);

                if (!string.IsNullOrEmpty(msg))
                {
                    throw new Exception(msg);
                }
                //Merge Osql data to string
                string      osqlStr = Utility.MergeOsqlResultData(dicOsqlXml);
                XmlDocument xmlDoc  = ObjectSerializeHelper.Deserialize <XmlDocument>(osqlStr);

                //Tranform to word
                TranformHelper.RenderFile(xmlDoc, Xsl);
            }
            catch (Exception)
            {
                MessageBox.Show(msg == string.Empty ? "Can't preview , check input data again !!!" : msg, "Error");
            }
        }
コード例 #9
0
ファイル: RenderService.cs プロジェクト: leonchen09/poc
        //extract the xml data file from excel archive file and import it into excel
        public bool mergeData(Workbook workbook)
        {
            String xmlcontent = null;
            XmlMap impMap     = null;

            foreach (XmlMap xmlmap in workbook.XmlMaps)
            {
                if (xmlmap.Name.Equals(GenXsd.PDE_XSD_MAP_NAME))
                {
                    impMap = xmlmap;
                    break;
                }
            }

            if (impMap == null)//cannot found import xsd, meaning this has been merged.
            {
                isFirstOpen = false;
                return(true);
            }

            foreach (CustomXMLPart curXmlPart in workbook.CustomXMLParts)
            {
                if (curXmlPart.BuiltIn)
                {
                    continue;
                }
                XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(curXmlPart.XML);
                if (customObject.ContentType == ContentType.PderXml)
                {
                    xmlcontent = customObject.Content;
                    break;
                }
            }
            if (xmlcontent == null || xmlcontent.Length < 1)
            {
                MessageBox.Show("The file format has been broken!");
                workbook.Close();
                return(false);
            }

            impMap.ImportXml(xmlcontent);
            //delete the xsd for import data
            impMap.Delete();
            workbook.Save();
            return(true);
        }
コード例 #10
0
ファイル: IntegrationManager.cs プロジェクト: leonchen09/poc
        /// <summary>
        /// Get internal bookmark object of active document
        /// </summary>
        /// <returns></returns>
        public void GetInternalBookmark(string key)
        {
            try
            {
                ManagerProfile mgrPro = Wkl.MainCtrl.ManagerCtrl.GetProfile(key);

                if (CurrentTemplateInfo.InternalBookmark.InternalBookmarkDomains.Count == 0)
                {
                    string customXmlPartId = GetCustomPartId();
                    string content         = GetCustomXmlPartContent(customXmlPartId);
                    if (string.IsNullOrEmpty(content))
                    {
                        CurrentTemplateInfo.InternalBookmark = new Core.InternalBookmark(true);
                        return;
                    }

                    XmlObject xmlObject = ObjectSerializeHelper.Deserialize <XmlObject>(content);
                    if (xmlObject == null)
                    {
                        CurrentTemplateInfo.InternalBookmark = new Core.InternalBookmark(true);
                        return;
                    }

                    content = xmlObject.Content;
                    if (!string.IsNullOrEmpty(content))
                    {
                        CurrentTemplateInfo.InternalBookmark =
                            ObjectSerializeHelper.Deserialize <Pdw.Core.InternalBookmark>(content);
                    }
                    else
                    {
                        CurrentTemplateInfo.InternalBookmark = new Core.InternalBookmark(true);
                    }
                }

                mgrPro.Ibm        = CurrentTemplateInfo.InternalBookmark;
                mgrPro.PdeContent = GetPdeContent();
            }
            catch (Exception ex)
            {
                ManagerException mgrExp = new ManagerException(ErrorCode.ipe_GetInternalBookmarkError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_GetInternalBookmarkError, ex.Message), ex.StackTrace);

                throw mgrExp;
            }
        }
コード例 #11
0
 public bool ReadMapInfo(Workbook workbook)
 {
     foreach (CustomXMLPart curXmlPart in workbook.CustomXMLParts)
     {
         if (curXmlPart.BuiltIn)
         {
             continue;
         }
         XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(curXmlPart.XML);
         if (customObject.ContentType == ContentType.PdeMapInfo)
         {
             String xmlcontent = customObject.Content;
             mapInfo = ObjectSerializeHelper.Deserialize <MapInfo>(xmlcontent);
             return(true);
         }
     }
     return(false);
 }
コード例 #12
0
 public bool ReadExportInfo(Workbook workbook)
 {
     foreach (CustomXMLPart curXmlPart in workbook.CustomXMLParts)
     {
         if (curXmlPart.BuiltIn)
         {
             continue;
         }
         XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(curXmlPart.XML);
         if (customObject.ContentType == ContentType.PdeExportItem)
         {
             String     xmlcontent = customObject.Content;
             PdeExports pdeExports = ObjectSerializeHelper.Deserialize <PdeExports>(xmlcontent);
             this.exportItems = pdeExports.items;
             return(true);
         }
     }
     return(false);
 }
コード例 #13
0
ファイル: Form1.cs プロジェクト: leonchen09/poc
        private void button13_Click(object sender, EventArgs e)
        {
            word.Application app      = createWord();
            String           wordFile = textBox10.Text;
            string           xsltFile = textBox9.Text;

            word.Document doc = app.Documents.Open(wordFile);
            //change properties of document
            //foreach (DocumentProperty docPro in doc.CustomDocumentProperties)
            //{
            //    if (docPro.Name.StartsWith("Pronto_ImportedExcelFileName"))
            //    {
            //        docPro.Value = textBox_pdwpder.Text;
            //    }
            //}
            //remove pde template and add pder file.
            string xsl = null;

            foreach (CustomXMLPart xmlPart in doc.CustomXMLParts)
            {
                if (xmlPart.BuiltIn)
                {
                    continue;
                }
                XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(xmlPart.XML);
                if (customObject.ContentType == ContentType.PdwrXsl)
                {
                    xsl = customObject.Content;
                    //xmlPart.Delete();
                    break;
                }
            }
            FileStream   fs = new FileStream(xsltFile, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);

            sw.Write(xsl);
            sw.Close();
            fs.Close();
            doc.Close();
            enablePdw(app);
            app.Quit();
        }
コード例 #14
0
ファイル: ConditionGoalSeek.cs プロジェクト: leonchen09/poc
 public bool ReadCGSInfo(Workbook workbook)
 {
     this.workbook = workbook;
     foreach (CustomXMLPart curXmlPart in workbook.CustomXMLParts)
     {
         if (curXmlPart.BuiltIn)
         {
             continue;
         }
         XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(curXmlPart.XML);
         if (customObject.ContentType == ContentType.PdeCondGoalSeekInfo)
         {
             String           xmlcontent = customObject.Content;
             CondGoalSeekInfo CGSInfo    = ObjectSerializeHelper.Deserialize <CondGoalSeekInfo>(xmlcontent);
             this.cgsInfo = CGSInfo;
             return(true);
         }
     }
     return(false);
 }
コード例 #15
0
ファイル: Form1.cs プロジェクト: leonchen09/poc
        private void button12_Click(object sender, EventArgs e)
        {
            word.Application app      = createWord();
            String           wordFile = textBox10.Text;
            string           xsltFile = textBox9.Text;

            word.Document doc = app.Documents.Open(wordFile);

            StreamReader sr  = new StreamReader(xsltFile);
            string       xsl = sr.ReadToEnd();

            //delete old xsl file
            foreach (CustomXMLPart xmlPart in doc.CustomXMLParts)
            {
                if (xmlPart.BuiltIn)
                {
                    continue;
                }
                XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(xmlPart.XML);
                if (customObject.ContentType == ContentType.PdwrXsl)
                {
                    xmlPart.Delete();
                    break;
                }
            }

            //add xsl file
            XmlObject xslObj = new XmlObject();

            xslObj.ContentType = ContentType.PdwrXsl;
            xslObj.Content     = xsl;
            CustomXMLPart xmlpart_xsl = doc.CustomXMLParts.Add();

            xmlpart_xsl.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(xslObj));

            sr.Close();
            doc.Save();
            enablePdw(app);
            app.Quit();
        }
コード例 #16
0
ファイル: IntegrationManager.cs プロジェクト: leonchen09/poc
        public void GetPdwrInformation(string key)
        {
            ManagerProfile mgrPro   = Wkl.MainCtrl.ManagerCtrl.GetProfile(key);
            PdwrInfo       pdwrInfo = new PdwrInfo();

            foreach (CustomXMLPart xmlPart in CommonProfile.ActiveDoc.CustomXMLParts)
            {
                string content = xmlPart.XML;
                try
                {
                    XmlObject xmlObject = ObjectSerializeHelper.Deserialize <XmlObject>(content);
                    switch (xmlObject.ContentType)
                    {
                    case ContentType.PdwrSettings:
                        pdwrInfo.SettingString = xmlObject.Content;
                        break;

                    case ContentType.PdwrXml:
                        pdwrInfo.XmlString = xmlObject.Content;
                        break;

                    case ContentType.PdwrXsl:
                        pdwrInfo.XsltString = xmlObject.Content;
                        break;

                    case ContentType.PdeContent:
                        pdwrInfo.PdeContent = xmlObject.Content;
                        break;

                    default:
                        break;
                    }
                }
                catch { }
            }

            mgrPro.PdwrInfo = pdwrInfo;
        }
コード例 #17
0
ファイル: IntegrationManager.cs プロジェクト: leonchen09/poc
        public void GetPdwInformation(string key)
        {
            try
            {
                ManagerProfile   mgrPro   = Wkl.MainCtrl.ManagerCtrl.GetProfile(key);
                List <XmlObject> contents = new List <XmlObject>();

                string osqlId = GetPropertyValue(PdwInfo.OsqlCustomXmlPartId);
                string xsltId = GetPropertyValue(PdwInfo.XsltCustomXmlPartId);
                string chksId = GetPropertyValue(PdwInfo.ChksCustomXmlPartId);

                string osql = GetCustomXmlPartContent(osqlId);
                string xslt = GetCustomXmlPartContent(xsltId);
                string chks = GetCustomXmlPartContent(chksId);

                contents.Add(ObjectSerializeHelper.Deserialize <XmlObject>(osql));
                contents.Add(ObjectSerializeHelper.Deserialize <XmlObject>(xslt));
                contents.Add(ObjectSerializeHelper.Deserialize <XmlObject>(chks));

                if (mgrPro.TemplateType == TemplateType.Pdm)
                {
                    string controlsId = GetPropertyValue(PdwInfo.PdmFormControlXmlPartId);
                    string controls   = GetCustomXmlPartContent(controlsId);
                    contents.Add(ObjectSerializeHelper.Deserialize <XmlObject>(controls));
                }

                mgrPro.XmlObjects = contents;
            }
            catch (Exception ex)
            {
                ManagerException mgrExp = new ManagerException(ErrorCode.ipe_GetPdwInfoError,
                                                               MessageUtils.Expand(Properties.Resources.ipe_GetPdwInfoError, ex.Message), ex.StackTrace);

                throw mgrExp;
            }
        }
コード例 #18
0
ファイル: ContextManager.cs プロジェクト: leonchen09/poc
        /// <summary>
        /// Oen pdwr file
        /// </summary>
        /// <param name="Doc"></param>
        public void OpenPdwr(Document Doc, ref List <string> tempFiles)
        {
            // get pdwr info
            string mgrKey = string.Empty;
            string srvKey = string.Empty;

            ServicesProfile srvPro = Wkl.MainCtrl.ServiceCtrl.CreateProfile(out srvKey);

            mainManager.MainService.PropertyService.GetPdwrInfos(srvKey);
            PdwrInfo pdwrInfo = srvPro.IntegrationService.PdwrInfo;

            // translate pdwr
            // if (!string.IsNullOrEmpty(pdwrInfo.XmlString) && !string.IsNullOrEmpty(pdwrInfo.XsltString))
            if (!string.IsNullOrEmpty(pdwrInfo.XmlString))
            {
                string folderPath = AssetManager.FileAdapter.TemporaryFolderPath;
                string fileName   = System.Guid.NewGuid().ToString();

                string xmlFilePath = string.Format("{0}\\{1}{2}", folderPath, fileName, FileExtension.Xml); // mwxml
                string xslFilePath = string.Format("{0}\\{1}{2}", folderPath, fileName, FileExtension.Xsl);

                FileHelper.CreateFile(xmlFilePath, pdwrInfo.XmlString);
                tempFiles.Add(xmlFilePath);
                if (!string.IsNullOrWhiteSpace(pdwrInfo.XsltString)) // support old file
                {
                    FileHelper.CreateFile(xslFilePath, pdwrInfo.XsltString);
                    tempFiles.Add(xslFilePath);
                }

                Document newDoc = null;
                if (!string.IsNullOrWhiteSpace(pdwrInfo.XsltString)) // support old file
                {
                    newDoc = Wkl.MainCtrl.CommonCtrl.CommonProfile.App.Documents.Open(
                        FileName: xmlFilePath,
                        Format: WdOpenFormat.wdOpenFormatXML,
                        XMLTransform: xslFilePath);
                }
                else
                {
                    newDoc = Wkl.MainCtrl.CommonCtrl.CommonProfile.App.Documents.Open(
                        FileName: xmlFilePath, Format: WdOpenFormat.wdOpenFormatXML);
                }
                Wkl.MainCtrl.CommonCtrl.CommonProfile.App.ScreenUpdating = true;
                newDoc.ActiveWindow.View.Type = WdViewType.wdPrintView;

                // update pde
                if (!string.IsNullOrWhiteSpace(pdwrInfo.PdeContent))
                {
                    PdeContent    pdeContent = ObjectSerializeHelper.Deserialize <PdeContent>(pdwrInfo.PdeContent);
                    List <string> excelFiles = mainManager.MainService.PropertyService.RenderPdeInPdw(newDoc, pdeContent);
                    tempFiles.AddRange(excelFiles);
                }
                newDoc.Save();

                #region process RenderSetting
                if (!string.IsNullOrEmpty(pdwrInfo.SettingString))
                {
                    RenderSettings renderSetting = ObjectSerializeHelper.Deserialize <RenderSettings>(pdwrInfo.SettingString);
                    if (renderSetting != null)
                    {
                        switch (renderSetting.Channel)
                        {
                            #region Media = Display
                        case RenderSettings.ChannelType.Display:
                            switch (renderSetting.Media)
                            {
                            case RenderSettings.MediaType.Pdf:
                                newDoc.ExportAsFixedFormat(Path.ChangeExtension(xmlFilePath, FileExtension.PdfNoDot),
                                                           WdExportFormat.wdExportFormatPDF, true);
                                ((_Document)newDoc).Close();
                                break;

                            case RenderSettings.MediaType.Xps:
                                newDoc.ExportAsFixedFormat(Path.ChangeExtension(xmlFilePath, FileExtension.XpsNoDot),
                                                           WdExportFormat.wdExportFormatXPS, true);
                                ((_Document)newDoc).Close();
                                break;

                            default:
                                break;
                            }
                            break;

                            #endregion
                            #region Media = Email, Media = Attachment
                        case RenderSettings.ChannelType.Email:
                        case RenderSettings.ChannelType.Attachment:
                            MailHelper.SendEmail(newDoc, renderSetting, ref tempFiles);
                            break;

                            #endregion
                            #region Media = Fax
                        case RenderSettings.ChannelType.Fax:
                            Wkl.MainCtrl.CommonCtrl.CommonProfile.App.CommandBars.ExecuteMso(
                                Constants.SendInternetFax);
                            break;

                            #endregion
                        default:
                            break;
                        }
                    }
                }

                #endregion
            }
        }
コード例 #19
0
ファイル: Form1.cs プロジェクト: leonchen09/poc
        private void button8_Click(object sender, EventArgs e)
        {
            word.Application app = new word.Application();
            app.Visible = true;

            Thread.Sleep(2000);

            //disable the pdw plugin
            COMAddIn  pdwAddin = null;
            COMAddIns addins   = app.COMAddIns;

            foreach (COMAddIn addin in addins)
            {
                if (addin.Description.Equals("Pdw"))
                {
                    addin.Connect = false;
                    pdwAddin      = addin;
                    break;
                }
            }
            Thread.Sleep(1000);
            string tempFile = textBox_pdw.Text;
            string wordFile = tempFile.Split('.')[0] + ".docx";

            File.Copy(tempFile, wordFile, true);
            word.Document doc = app.Documents.Open(wordFile);
            //change properties of document
            //foreach (DocumentProperty docPro in doc.CustomDocumentProperties)
            //{
            //    if (docPro.Name.StartsWith("Pronto_ImportedExcelFileName"))
            //    {
            //        docPro.Value = textBox_pdwpder.Text;
            //    }
            //}
            //remove pde template and add pder file.
            PdeContent pdeImported = null;
            string     xsl         = null;

            foreach (CustomXMLPart xmlPart in doc.CustomXMLParts)
            {
                if (xmlPart.BuiltIn)
                {
                    continue;
                }
                XmlObject customObject = ObjectSerializeHelper.Deserialize <XmlObject>(xmlPart.XML);
                if (customObject.ContentType == ContentType.ImportedPde)
                {
                    pdeImported = ObjectSerializeHelper.Deserialize <PdeContent>(customObject.Content);
                }
                else if (customObject.ContentType == ContentType.Xslt)
                {
                    xsl = customObject.Content;
                }
                xmlPart.Delete();
            }
            //add pder file
            CustomXMLPart xmlPart_pder = doc.CustomXMLParts.Add();

            pdeImported.FileContent = FileHelper.ExcelToBase64(textBox_pdwpder.Text);
            //pdeImported.FullFileName = textBox_pdwpder.Text;
            XmlObject pderObj = new XmlObject();

            pderObj.ContentType = ContentType.ImportedPde;
            pderObj.Content     = ObjectSerializeHelper.SerializeToString <PdeContent>(pdeImported);
            xmlPart_pder.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(pderObj));
            //add xml data file
            XmlDocument dataXml = new XmlDocument();

            dataXml.Load(textBox_pdwd.Text);
            XmlObject     pdwrXml     = new XmlObject(dataXml.InnerXml, ContentType.PdwrXml);
            CustomXMLPart xmlPart_xml = doc.CustomXMLParts.Add();

            xmlPart_xml.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(pdwrXml));
            //add xsl file
            XmlObject xslObj = new XmlObject();

            xslObj.ContentType = ContentType.PdwrXsl;
            xslObj.Content     = xsl;
            CustomXMLPart xmlpart_xsl = doc.CustomXMLParts.Add();

            xmlpart_xsl.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(xslObj));
            //add pdwr setting
            XmlObject settObj = new XmlObject();

            settObj.ContentType = ContentType.PdwrSettings;
            settObj.Content     = "<?xml version=\"1.0\" encoding=\"utf-16\"?><RenderSettings xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Media>Docx</Media><Channel>Display</Channel></RenderSettings>";
            CustomXMLPart xmlpart_sett = doc.CustomXMLParts.Add();

            xmlpart_sett.LoadXML(ObjectSerializeHelper.SerializeToString <XmlObject>(settObj));

            doc.Save();
            doc.Close();
            pdwAddin.Connect = true;
            app.Quit();
            File.Copy(wordFile, wordFile.Split('.')[0] + ".pdwr", true);
            MessageBox.Show("Create pdwr file success.");
        }