internal powerPnt.Presentation prepareFontPPT(string fontName, float fontsize, string filenameSaveAs = "") { if (filenameSaveAs == "") { filenameSaveAs = fontName + "(不含缺字).pptm"; } //DirFiles df = new DirFiles(); //powerPnt.Presentation ppt = df.get字圖母片pptm(); powerPnt.Presentation ppt = new DirFiles().get字圖母片pptm(); ppt.Slides[2].Shapes[1].TextFrame.TextRange.Font.NameFarEast = fontName; ppt.Slides[2].Shapes[1].TextFrame.TextRange.Font.Size = fontsize; ppt.SaveAs(DirFiles.getCjk_basic_IDS_UCS_Basic_txt().DirectoryName + "\\" + filenameSaveAs); //ppt.Application.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;//沒有這行一樣會現出現來,與Word不同。 return(ppt); }
getFontCharacterset(string fontName) {//準備好各字型檔(不含缺字)相關者 //https://www.google.com/search?q=c%23+%E8%AE%80%E5%8F%96txt&rlz=1C1JRYI_enTW948TW948&sxsrf=ALeKk00EZy0V-LIAiQBz6f5tr6PPx2AI4w%3A1618768409405&ei=GXJ8YKmVGIu9mAW1io6QDw&oq=c%23+%E8%AE%80%E5%8F%96&gs_lcp=Cgdnd3Mtd2l6EAMYADICCAAyAggAMgIIADICCAAyAggAMgIIADICCAAyAggAMgIIADICCAA6BQgAELADOgQIIxAnOgQIABBDOgcIABCxAxBDOgQIABAeOgYIABAIEB46CAgAEAgQChAeULWyUlih0FNg-uhTaAtwAHgBgAGPBogB2gmSAQU3LjYtMZgBAKABAaoBB2d3cy13aXrIAQHAAQE&sclient=gws-wiz App app = new App(); winWord.Application appDoc = app.AppDoc; winWord.Document d; try { d = appDoc.Documents.Add(""); } catch { app.AppDoc = null; appDoc = app.AppDoc; d = appDoc.Documents.Add(""); } //d.ActiveWindow.Visible = true; using (StreamReader sr = new StreamReader(DirFiles.getCjk_basic_IDS_UCS_Basic_txt().FullName)) d.Range().Text = sr.ReadToEnd(); //sr在出此行後即會調用Dispose()清除記憶體 d.Range().Font.NameFarEast = fontName; string docName = DirFiles.getDir各字型檔相關() + "\\" + fontName + "(不含缺字).docx"; if (File.Exists(docName)) { DialogResult dr = MessageBox.Show("檔名重複!請檢查,再繼續...是否沿用舊檔?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (dr == DialogResult.Cancel) { if (app.DocAppOpenByCode) { appDoc.Quit(winWord. WdSaveOptions.wdDoNotSaveChanges); } appDoc = null; Application.OpenForms[0].BackColor = Color.White; return(null); }//沿用舊檔 d.Close(winWord.WdSaveOptions.wdDoNotSaveChanges); return(appDoc.Documents.Open(docName)); } else//不存在舊檔 { d.SaveAs2(docName); FontsOpsDoc.removeNoFont(d, fontName); d.Save(); return(d); } }
private void goFontsCharsToPics() { try { string chDir = DirFiles.searchRootDirChange(textBox1.Text); if (chDir == "") { MessageBox.Show("並無此目錄,請確認後再執行!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (textBox1.Text != chDir) { textBox1.Text = chDir; } BackColor = Color.Gray; this.Enabled = false; button1.Enabled = false; string fontname = textBox2.Text; WinWord.Document wd = new fontsPics().getFontCharacterset (fontname); if (wd != null) { BackColor = Color.Red; string picFolder = textBox1.Text; if (picFolder.IndexOf(fontname) == -1) { picFolder += ("\\" + fontname + "\\"); } powerPnt.Presentation ppt = new fontsPics().prepareFontPPT(fontname, float.Parse(textBox3.Text)); new fontsPics().addCharsSlidesExportPng(wd, ppt, picFolder, Int32.Parse(textBox4.Text)); FileInfo wdf = new FileInfo(wd.FullName); WinWord.Application wdApp = wd.Application; wd.Close();//執行完成,關閉因程式而開啟的Word if (!wdApp.UserControl) { wdApp.Quit(); } //移動已完成的檔案到已完成資料夾下 string destFilename = wdf.Directory.FullName + "\\done已完成\\" + wdf.Name; if (!File.Exists(destFilename)) { wdf.MoveTo(destFilename); } if (BackColor != Color.BurlyWood)//若字圖與字型字數無不同,才顯示綠底色 { BackColor = Color.Green; } warnings.playSound(); } this.Enabled = true; button1.Enabled = true; } catch (Exception e) { printExceptiontoDoc(e); this.Enabled = true; button1.Enabled = true; } }