public static new Boolean Convert(String inputFile, String outputFile) { Microsoft.Office.Interop.Publisher.Application app; String tmpFile = null; try { app = new Microsoft.Office.Interop.Publisher.Application(); app.Open(inputFile, false, false, PbSaveOptions.pbDoNotSaveChanges); // Try and avoid dialogs about versions tmpFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".pub"; app.ActiveDocument.SaveAs(tmpFile, PbFileFormat.pbFilePublication, false); app.ActiveDocument.ExportAsFixedFormat(PbFixedFormatType.pbFixedFormatTypePDF, outputFile, PbFixedFormatIntent.pbIntentStandard, true); app.ActiveDocument.Close(); ((Microsoft.Office.Interop.Publisher._Application)app).Quit(); return true; } catch (Exception e) { Console.WriteLine(e.Message); return false; } finally { if (tmpFile != null) { System.IO.File.Delete(tmpFile); } app = null; } }
public static new Boolean Convert(String inputFile, String outputFile) { Microsoft.Office.Interop.Publisher.Application app; String tmpFile = null; try { app = new Microsoft.Office.Interop.Publisher.Application(); app.Open(inputFile, false, false, PbSaveOptions.pbDoNotSaveChanges); // Try and avoid dialogs about versions tmpFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".pub"; app.ActiveDocument.SaveAs(tmpFile, PbFileFormat.pbFilePublication, false); app.ActiveDocument.ExportAsFixedFormat(PbFixedFormatType.pbFixedFormatTypePDF, outputFile, PbFixedFormatIntent.pbIntentStandard, true); app.ActiveDocument.Close(); ((Microsoft.Office.Interop.Publisher._Application)app).Quit(); return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } finally { if (tmpFile != null) { System.IO.File.Delete(tmpFile); } app = null; } }
public static async Task RunMsPublisher() { //Thread.Sleep(40000); if (ShowWindow) { Console.WriteLine("Checking for Certificates"); } var certs = await CertRepository.GetNewCertificatesAsync(); var batchId = DateTime.Now.ToString("yyyyMMdd-HHmm"); if (ShowWindow) { Console.WriteLine(certs.Count() + " Found. Batch Id = " + batchId); } if (!certs.Any()) { return; } foreach (var cert in certs) { Console.WriteLine(cert.ID + " - " + cert.CertType + " - " + cert.Dojo + " = " + cert.FullName + " = " + batchId); } var app = new Application(); app.ActiveWindow.Visible = true; LogData.LogLine("BATCH: " + batchId, batchId); LogData.LogLine("==============================", batchId); LogData.LogLine($" ", batchId); LogData.LogLine($" ", batchId); foreach (vwCertificate certificate in certs) { certificate.BatchID = batchId; await PrintOutCertificateAsync(app, certificate); LogData.LogLine($"{certificate.ID}: {certificate.CertType} - {certificate.Dojo} - {certificate.FullName} - ", batchId); } LogData.LogLine($" ", batchId); LogData.LogLine($" ", batchId); LogData.LogLine("==============================", batchId); LogData.LogLine("TOTAL CERTS: " + certs.Count().ToString(), batchId); LogData.PrintFile(batchId); app.Quit(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); }
public void Dispose() { if (_appPub != null) { _appPub.Quit(); _appPub = null; GC.Collect(); } }
public static new int Convert(String inputFile, String outputFile, Hashtable options) { Boolean running = (Boolean)options["noquit"]; Microsoft.Office.Interop.Publisher.Application app = null; String tmpFile = null; try { try { app = (Microsoft.Office.Interop.Publisher.Application)Marshal.GetActiveObject("Publisher.Application"); } catch (System.Exception) { app = new Microsoft.Office.Interop.Publisher.Application(); running = false; } Boolean nowrite = (Boolean)options["readonly"]; bool pdfa = (Boolean)options["pdfa"] ? true : false; if ((Boolean)options["hidden"]) { var activeWin = app.ActiveWindow; activeWin.Visible = false; Converter.ReleaseCOMObject(activeWin); } app.Open(inputFile, nowrite, false, PbSaveOptions.pbDoNotSaveChanges); PbFixedFormatIntent quality = PbFixedFormatIntent.pbIntentStandard; if ((Boolean)options["print"]) { quality = PbFixedFormatIntent.pbIntentPrinting; } if ((Boolean)options["screen"]) { quality = PbFixedFormatIntent.pbIntentMinimum; } Boolean includeProps = !(Boolean)options["excludeprops"]; Boolean includeTags = !(Boolean)options["excludetags"]; // Try and avoid dialogs about versions tmpFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".pub"; var activeDocument = app.ActiveDocument; activeDocument.SaveAs(tmpFile, PbFileFormat.pbFilePublication, false); activeDocument.ExportAsFixedFormat(PbFixedFormatType.pbFixedFormatTypePDF, outputFile, quality, includeProps, -1, -1, -1, -1, -1, -1, -1, true, PbPrintStyle.pbPrintStyleDefault, includeTags, true, pdfa); activeDocument.Close(); Converter.ReleaseCOMObject(activeDocument); return((int)ExitCode.Success); } catch (Exception e) { Console.WriteLine(e.Message); return((int)ExitCode.UnknownError); } finally { if (tmpFile != null) { System.IO.File.Delete(tmpFile); } if (app != null) { ((Microsoft.Office.Interop.Publisher._Application)app).Quit(); } Converter.ReleaseCOMObject(app); } }
internal bool Import(string xmlFilePath, string pubFilePath, string imagePath, SettingsCore settings) { bool success = false; pub2xml.api.Processor.ProcessingErrors = new List <Structures.Core.TextFrame>(); pub2xml.api.Processor.MaximumShapes = 0; pub2xml.api.Processor.CurrentIndex = 0; pub2xml.api.Processor.FramesDictoinary = null; string fileName = pubFilePath; if (settings.ImportCreateBakFile) { string fileNameBak = pubFilePath + Constants.pub2xmlBakExtension; if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.CreatingBackupFile); } if (File.Exists(fileNameBak)) { File.Delete(fileNameBak); } File.Copy(fileName, fileNameBak, true); } if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.LoadingXmlFile); } Structures.Core.ExportPackage ep = ReadExportPackage(xmlFilePath); pub2xml.api.Processor.FramesDictoinary = new Dictionary <long, List <Structures.Core.TextFrame> >(); foreach (Structures.Core.TextFrame tf in ep.textFrames) { if (pub2xml.api.Processor.FramesDictoinary.ContainsKey(tf.shapeId)) { pub2xml.api.Processor.FramesDictoinary[tf.shapeId].Add(tf); } else { pub2xml.api.Processor.FramesDictoinary.Add(tf.shapeId, new List <Structures.Core.TextFrame> { tf }); } } Microsoft.Office.Interop.Publisher.Application pbApp = new Microsoft.Office.Interop.Publisher.Application(); pbApp.Options.AutoHyphenate = false; try { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.LoadingPublisherFile); } Microsoft.Office.Interop.Publisher.Document pbDoc = pbApp.Open(pubFilePath, false, false, PbSaveOptions.pbDoNotSaveChanges); #region | get total shapes count | foreach (Microsoft.Office.Interop.Publisher.Page page in pbDoc.MasterPages) { foreach (Microsoft.Office.Interop.Publisher.Shape shape in page.Shapes) { pub2xml.api.Processor.MaximumShapes++; } } foreach (Microsoft.Office.Interop.Publisher.Page page in pbDoc.Pages) { foreach (Microsoft.Office.Interop.Publisher.Shape shape in page.Shapes) { pub2xml.api.Processor.MaximumShapes++; } } #endregion try { #region | MasterPages | foreach (Microsoft.Office.Interop.Publisher.Page page in pbDoc.MasterPages) { foreach (Microsoft.Office.Interop.Publisher.Shape shape in page.Shapes) { pub2xml.api.Processor.CurrentIndex++; if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.BuildingShape + ": " + shape.ID + ", " + shape.Name + "..."); } try { List <Structures.Core.TextFrame> tfs = setTextFramesFromShape(shape, imagePath, settings); if (tfs.Count > 0) { ep.textFrames.AddRange(tfs); } } catch (Exception ex) { throw ex; } } } #endregion #region | Pages | foreach (Microsoft.Office.Interop.Publisher.Page page in pbDoc.Pages) { foreach (Microsoft.Office.Interop.Publisher.Shape shape in page.Shapes) { pub2xml.api.Processor.CurrentIndex++; if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.BuildingShape + ": " + shape.ID + ", " + shape.Name + "..."); } try { List <Structures.Core.TextFrame> tfs = setTextFramesFromShape(shape, imagePath, settings); if (tfs.Count > 0) { ep.textFrames.AddRange(tfs); } } catch (Exception ex) { throw ex; } if (pub2xml.api.Processor.CurrentIndex % 100 == 0) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.CurrentIndex, StringResources.SavingChanges); } pbDoc.Save(); } } } #endregion if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.ApplyingInternalFontStyles); } #region | apply internal font information | Cache.settings.FontFormatTags.ForEach(a => { pbDoc.Find.FindText = "<" + a.name + ">"; pbDoc.Find.ReplaceScope = PbReplaceScope.pbReplaceScopeAll; pbDoc.Find.ReplaceWithText = ""; pbDoc.Find.Execute(); pbDoc.Find.FindText = "</" + a.name + ">"; pbDoc.Find.ReplaceScope = PbReplaceScope.pbReplaceScopeAll; pbDoc.Find.ReplaceWithText = ""; pbDoc.Find.Execute(); }); #endregion success = true; } catch (Exception ex) { throw ex; } finally { if (success) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.SavingPublisherFile); } pbDoc.Save(); #region | create pdf | if (settings.ImportCreatePdfFile) { if (_onChange_Progress != null) { _onChange_Progress(pub2xml.api.Processor.MaximumShapes, pub2xml.api.Processor.MaximumShapes, StringResources.SavingPDFFile); } pbDoc.ExportAsFixedFormat(PbFixedFormatType.pbFixedFormatTypePDF, pubFilePath + Constants.pub2xmlPDFAfterImportExtension); } #endregion } pbDoc.Close(); pbDoc = null; } } catch (Exception ex) { throw ex; } finally { pbApp = null; GC.Collect(); Process[] Processes = Process.GetProcessesByName("MSPUB"); foreach (Process p in Processes) { if (p.MainWindowTitle.Trim() == "") { p.Kill(); } } } return(success); }
public void runInForm() { ed.addDebug("Exporting " + file + "..."); String tempDir = getTempDir(); ed.addDebug("Tempoary Directory: " + tempDir); if (this.method == "handouts") { Package zipPresentation = null; if (options.Contains("exportNotes")) { String tmpFile = Path.Combine(tempDir, "pres.zip"); File.Copy(file, tmpFile); zipPresentation = ZipPackage.Open(new FileStream(tmpFile, FileMode.Open)); } Microsoft.Office.Interop.PowerPoint.Application powerPoint = openPowerPoint(); ed.addDebug("PowerPoint should have loaded document"); ed.addDebug("Exporting as handouts..."); Presentation toExport = powerPoint.Presentations[1]; ed.addDebug("Opening Publisher Template"); Microsoft.Office.Interop.Publisher.Application publisher = new Microsoft.Office.Interop.Publisher.Application(); String pubFile = Path.Combine(tempDir, "out.pub"); File.Copy(Path.Combine( Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Templates", "Handout-3P.pub" // TODO: Add option for different templates ), pubFile); Document publisherDoc = publisher.Open( pubFile ); publisher.ActiveWindow.Visible = true; int slideWidth = (int) toExport.PageSetup.SlideWidth; int slideHeight = (int)toExport.PageSetup.SlideHeight; int slideCount = 1, onPage = 1; publisherDoc.Pages[onPage].Duplicate(); foreach(_Slide slide in toExport.Slides){ if (slideCount == 4) // End of Page but only create a new one, if there is more! { publisherDoc.Pages[onPage + 1].Duplicate(); onPage += 1; slideCount = 1; } ed.addDebug("Exporting slide #" + slide.SlideNumber); String fname = Path.Combine(tempDir, slide.SlideNumber + "-ppt.png"); slide.Export(fname, "png"); String notes = ""; if (options.Contains("exportNotes")) { // I HATE YOU POWERPOINT! Uri partUriResource = PackUriHelper.CreatePartUri( new Uri(@"ppt/notesSlides/notesSlide" + slide.SlideNumber + ".xml", UriKind.Relative)); if (zipPresentation.PartExists(partUriResource)) { Stream noteStream = zipPresentation.GetPart(partUriResource).GetStream(FileMode.Open, FileAccess.Read); StreamReader nSR = new StreamReader(noteStream); // Strip crap notes = nSR.ReadToEnd(); // Chop out slide numbers. I don't have a clue really :') int s = notes.IndexOf("<p:txBody>"); if (s != -1) { notes = notes.Substring(s, notes.IndexOf("</p:txBody>") - s); notes = (new Regex("<[^>]*>")).Replace(notes, ""); } nSR.Close(); noteStream.Close(); } } foreach (Microsoft.Office.Interop.Publisher.Shape shape in publisherDoc.Pages[onPage].Shapes) { if (shapeHasTag(shape, "Picture "+ slideCount)) { shape.Fill.UserPicture(fname); } else if (shapeHasTag(shape, "Text " + slideCount)) { shape.TextFrame.AutoFitText = PbTextAutoFitType.pbTextAutoFitBestFit; shape.TextFrame.TextRange.Text = notes; } } slideCount += 1; } publisherDoc.Pages[publisherDoc.Pages.Count].Delete(); toExport.Close(); ed.addDebug("Exported as handouts :)"); } ed.finishJob(""); }
public static new int Convert(String inputFile, String outputFile, Hashtable options) { Boolean running = (Boolean)options["noquit"]; Microsoft.Office.Interop.Publisher.Application app = null; String tmpFile = null; try { try { app = (Microsoft.Office.Interop.Publisher.Application)Marshal.GetActiveObject("Publisher.Application"); } catch (System.Exception) { app = new Microsoft.Office.Interop.Publisher.Application(); running = false; } Boolean nowrite = (Boolean)options["readonly"]; bool pdfa = (Boolean)options["pdfa"] ? true : false; if ((Boolean)options["hidden"]) { var activeWin = app.ActiveWindow; activeWin.Visible = false; Converter.releaseCOMObject(activeWin); } app.Open(inputFile, nowrite, false, PbSaveOptions.pbDoNotSaveChanges); PbFixedFormatIntent quality = PbFixedFormatIntent.pbIntentStandard; if ((Boolean)options["print"]) { quality = PbFixedFormatIntent.pbIntentPrinting; } if ((Boolean)options["screen"]) { quality = PbFixedFormatIntent.pbIntentMinimum; } Boolean includeProps = !(Boolean)options["excludeprops"]; Boolean includeTags = !(Boolean)options["excludetags"]; // Try and avoid dialogs about versions tmpFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".pub"; var activeDocument = app.ActiveDocument; activeDocument.SaveAs(tmpFile, PbFileFormat.pbFilePublication, false); activeDocument.ExportAsFixedFormat(PbFixedFormatType.pbFixedFormatTypePDF, outputFile, quality, includeProps, -1, -1, -1, -1, -1, -1, -1, true, PbPrintStyle.pbPrintStyleDefault, includeTags, true, pdfa); activeDocument.Close(); Converter.releaseCOMObject(activeDocument); return (int)ExitCode.Success; } catch (Exception e) { Console.WriteLine(e.Message); return (int)ExitCode.UnknownError; } finally { if (tmpFile != null) { System.IO.File.Delete(tmpFile); } if (app != null) { ((Microsoft.Office.Interop.Publisher._Application)app).Quit(); } Converter.releaseCOMObject(app); } }
public PublisherToPdf() { _appPub = new Microsoft.Office.Interop.Publisher.Application(); }
public void runInForm() { ed.addDebug("Exporting " + file + "..."); String tempDir = getTempDir(); ed.addDebug("Tempoary Directory: " + tempDir); if (this.method == "handouts") { Package zipPresentation = null; if (options.Contains("exportNotes")) { String tmpFile = Path.Combine(tempDir, "pres.zip"); File.Copy(file, tmpFile); zipPresentation = ZipPackage.Open(new FileStream(tmpFile, FileMode.Open)); } Microsoft.Office.Interop.PowerPoint.Application powerPoint = openPowerPoint(); ed.addDebug("PowerPoint should have loaded document"); ed.addDebug("Exporting as handouts..."); Presentation toExport = powerPoint.Presentations[1]; ed.addDebug("Opening Publisher Template"); Microsoft.Office.Interop.Publisher.Application publisher = new Microsoft.Office.Interop.Publisher.Application(); String pubFile = Path.Combine(tempDir, "out.pub"); File.Copy(Path.Combine( Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Templates", "Handout-3P.pub" // TODO: Add option for different templates ), pubFile); Document publisherDoc = publisher.Open(pubFile); publisher.ActiveWindow.Visible = true; int slideWidth = (int)toExport.PageSetup.SlideWidth; int slideHeight = (int)toExport.PageSetup.SlideHeight; int slideCount = 1, onPage = 1; publisherDoc.Pages[onPage].Duplicate(); foreach (_Slide slide in toExport.Slides) { if (slideCount == 4) // End of Page but only create a new one, if there is more! { publisherDoc.Pages[onPage + 1].Duplicate(); onPage += 1; slideCount = 1; } ed.addDebug("Exporting slide #" + slide.SlideNumber); String fname = Path.Combine(tempDir, slide.SlideNumber + "-ppt.png"); slide.Export(fname, "png"); String notes = ""; if (options.Contains("exportNotes")) { // I HATE YOU POWERPOINT! Uri partUriResource = PackUriHelper.CreatePartUri( new Uri(@"ppt/notesSlides/notesSlide" + slide.SlideNumber + ".xml", UriKind.Relative)); if (zipPresentation.PartExists(partUriResource)) { Stream noteStream = zipPresentation.GetPart(partUriResource).GetStream(FileMode.Open, FileAccess.Read); StreamReader nSR = new StreamReader(noteStream); // Strip crap notes = nSR.ReadToEnd(); // Chop out slide numbers. I don't have a clue really :') int s = notes.IndexOf("<p:txBody>"); if (s != -1) { notes = notes.Substring(s, notes.IndexOf("</p:txBody>") - s); notes = (new Regex("<[^>]*>")).Replace(notes, ""); } nSR.Close(); noteStream.Close(); } } foreach (Microsoft.Office.Interop.Publisher.Shape shape in publisherDoc.Pages[onPage].Shapes) { if (shapeHasTag(shape, "Picture " + slideCount)) { shape.Fill.UserPicture(fname); } else if (shapeHasTag(shape, "Text " + slideCount)) { shape.TextFrame.AutoFitText = PbTextAutoFitType.pbTextAutoFitBestFit; shape.TextFrame.TextRange.Text = notes; } } slideCount += 1; } publisherDoc.Pages[publisherDoc.Pages.Count].Delete(); toExport.Close(); ed.addDebug("Exported as handouts :)"); } ed.finishJob(""); }
private bool checkPub() { GC.Collect(); GC.WaitForPendingFinalizers(); if (pubApp != null) { Marshal.FinalReleaseComObject(pubApp); } try { pubApp = (Publisher.Application)Marshal.GetActiveObject("Publisher.Application"); } catch (COMException ex) { Logger.log(TraceEventType.Error, 9, "Publisher Exception\r\n" + ex.GetType() + ":" + ex.Message + "\r\n" + ex.StackTrace); statusLabel.Content = "Publisher couldn't be accessed. Publisher not open?"; return false; } if (pubApp == null) { statusLabel.Content = "Publisher couldn't be accessed. Publisher not open?"; return false; } return true; }
/// <summary> /// Converts Расписашка (*.db) database file with schedule to Microsoft Office Publisher 2010 (*.pub) file /// </summary> /// <param name="inPath">full path to Расписашка (*.db) database file with schedule</param> /// <param name="outPath">full path to Публикация Publisher 2010 (*.pub) publication file with converted schedule</param> /// <param name="backWorker">BackgroundWorker for reporting progress</param> /// <returns>full path to converted Microsoft Office Publisher 2010 (*.pub) file</returns> private string convertDatabase(string inPath, string outPath, BackgroundWorker backWorker) { string savePath = inPath.Substring(0, inPath.Length - 3) + ".pub"; SQLiteConnection dbConnection = new SQLiteConnection("Data Source=" + inPath + ";Version=3"); dbConnection.Open(); const string command = "SELECT names_1.name AS teacher_short, names_1.full_name AS teacher, lessons._id, lessons.day, lessons.number, names.name AS subject, names_2.name AS place, names_3.name AS type, lessons.weeks, lessons.kind_id AS type_id" + " FROM lessons, names, names names_1, names names_2, names names_3" + " WHERE lessons.name_id = names._id AND lessons.teacher_id = names_1._id AND lessons.place_id = names_2._id AND lessons.kind_id = names_3._id"; SQLiteCommand dbCommand = new SQLiteCommand(command, dbConnection); SQLiteDataReader dbReader = dbCommand.ExecuteReader(); Publisher.Application publisherApp = new Publisher.Application(); publisherApp.ScreenUpdating = false; Publisher.Document document = publisherApp.ActiveDocument; Publisher.Window publisherWindow = publisherApp.ActiveWindow; //publisherWindow.Caption = "Schedule"; //publisherWindow.WindowState = Publisher.PbWindowState.pbWindowStateMaximize; //publisherWindow.Visible = false; // Setup design document.PageSetup.PageWidth = publisherApp.CentimetersToPoints(PAGE_A4_WIDTH); document.PageSetup.PageHeight = publisherApp.CentimetersToPoints(PAGE_A4_HEIGHT); //Publisher.Page page = document.Pages.Add(1, 0); Publisher.Page page = document.Pages[1]; // Create tables Publisher.Shape[] shapes = new Publisher.Shape[10]; Publisher.Table[] tables = new Publisher.Table[10]; float[] positionsX = { 0.5f, 10.25f, 20.0f, 0.5f, 10.25f, 0.5f, 10.25f, 20.0f, 0.5f, 10.25f }; float[] positionsY = { 0.5f, 0.5f, 0.5f, 5.6f, 5.6f, 10.75f, 10.75f, 10.75f, 15.85f, 15.85f }; string[] weekDays = { "Понедельник", "Вторник", "Среда", "Четверг", "Пятница" }; for (int i = 0; i < 10; i++) { Publisher.Shape shape = page.Shapes.AddTable(6, 5, publisherApp.CentimetersToPoints(positionsX[i]), publisherApp.CentimetersToPoints(positionsY[i]), publisherApp.CentimetersToPoints(9.25f), publisherApp.CentimetersToPoints(4.6f)); Publisher.Table table = shape.Table; shapes[i] = shape; tables[i] = table; table.Rows[1].Cells.Merge(); // Setup rows/cols sizes table.Columns[1].Width = publisherApp.CentimetersToPoints(0.425f); table.Columns[2].Width = publisherApp.CentimetersToPoints(0.425f); table.Columns[3].Width = publisherApp.CentimetersToPoints(3.625f); table.Columns[4].Width = publisherApp.CentimetersToPoints(1.375f); table.Columns[5].Width = publisherApp.CentimetersToPoints(3.4f); table.Rows[1].Height = publisherApp.CentimetersToPoints(0.63f); table.Rows[2].Height = publisherApp.CentimetersToPoints(0.62f); table.Rows[3].Height = publisherApp.CentimetersToPoints(0.62f); table.Rows[4].Height = publisherApp.CentimetersToPoints(0.62f); table.Rows[5].Height = publisherApp.CentimetersToPoints(0.62f); table.Rows[6].Height = publisherApp.CentimetersToPoints(1.45f); table.GrowToFitText = false; // Setup borders foreach (Publisher.Cell tcell in table.Cells) { tcell.BorderLeft.Weight = 1.0f; tcell.BorderTop.Weight = 1.0f; tcell.BorderRight.Weight = 1.0f; tcell.BorderBottom.Weight = 1.0f; } Publisher.Cell cell = table.Rows[1].Cells[1]; cell.VerticalTextAlignment = Publisher.PbVerticalTextAlignmentType.pbVerticalTextAlignmentCenter; cell.BorderLeft.Weight = 1.0f; cell.BorderTop.Weight = 1.0f; cell.BorderRight.Weight = 1.0f; cell.BorderBottom.Weight = 1.0f; Publisher.TextRange cellText = cell.TextRange; cellText.Text = weekDays[i % 5]; cellText.ParagraphFormat.Alignment = Publisher.PbParagraphAlignmentType.pbParagraphAlignmentCenter; cellText.Font.Name = "Arial"; cellText.Font.Bold = MsoTriState.msoTrue; cellText.Font.Italic = MsoTriState.msoTrue; //cellText.ParagraphFormat.SpaceAfter = 0.0f; //cellText.ParagraphFormat.LineSpacing = 1.0f; //cellText.ParagraphFormat.SpaceBefore = 0.0f; for (int j = 0; j < 5; j++) { cell = table.Rows[j + 2].Cells[2]; cell.VerticalTextAlignment = Publisher.PbVerticalTextAlignmentType.pbVerticalTextAlignmentCenter; cellText = cell.TextRange; cellText.ParagraphFormat.Alignment = Publisher.PbParagraphAlignmentType.pbParagraphAlignmentCenter; cellText.Font.Name = "Arial"; cellText.Font.Bold = MsoTriState.msoTrue; //cellText.ParagraphFormat.SpaceAfter = 0.0f; //cellText.ParagraphFormat.LineSpacing = 1.0f; //cellText.ParagraphFormat.SpaceBefore = 0.0f; cellText.Text = (j + 1).ToString(); } backWorker.ReportProgress((int)(i / 10.0f * 75)); } // Fill data string subject, place, teacher_short; long type_id; string week; long day, number; int index; int counter = 0; while (dbReader.Read()) { subject = (string)dbReader["subject"]; place = (string)dbReader["place"]; teacher_short = (string)dbReader["teacher_short"]; type_id = (long)dbReader["type_id"]; week = (string)dbReader["weeks"]; if (week == "a") // all: 1,2,3,... { day = (long)dbReader["day"]; number = (long)dbReader["number"]; index = (int)day - 1; tables[index].Rows[(int)number + 1].Cells[1].TextRange.Text = (type_id == 1 ? "+" : ""); tables[index].Rows[(int)number + 1].Cells[3].TextRange.Text = subject; tables[index].Rows[(int)number + 1].Cells[4].TextRange.Text = place; tables[index].Rows[(int)number + 1].Cells[5].TextRange.Text = teacher_short; index = (int)day + 4; tables[index].Rows[(int)number + 1].Cells[1].TextRange.Text = (type_id == 1 ? "+" : ""); tables[index].Rows[(int)number + 1].Cells[3].TextRange.Text = subject; tables[index].Rows[(int)number + 1].Cells[4].TextRange.Text = place; tables[index].Rows[(int)number + 1].Cells[5].TextRange.Text = teacher_short; } else if (week == "e") // even: 2,4,6,... { day = (long)dbReader["day"]; number = (long)dbReader["number"]; index = (int)day + 4; tables[index].Rows[(int)number + 1].Cells[1].TextRange.Text = (type_id == 1 ? "+" : ""); tables[index].Rows[(int)number + 1].Cells[3].TextRange.Text = subject; tables[index].Rows[(int)number + 1].Cells[4].TextRange.Text = place; tables[index].Rows[(int)number + 1].Cells[5].TextRange.Text = teacher_short; } else if (week == "o") // odd: 1,3,5,... { day = (long)dbReader["day"]; number = (long)dbReader["number"]; index = (int)day - 1; tables[index].Rows[(int)number + 1].Cells[1].TextRange.Text = (type_id == 1 ? "+" : ""); tables[index].Rows[(int)number + 1].Cells[3].TextRange.Text = subject; tables[index].Rows[(int)number + 1].Cells[4].TextRange.Text = place; tables[index].Rows[(int)number + 1].Cells[5].TextRange.Text = teacher_short; } backWorker.ReportProgress((int)(++counter / (float)dbReader.StepCount * 24 + 75)); } publisherWindow.Caption = "Schedule"; publisherWindow.Visible = true; publisherWindow.WindowState = Publisher.PbWindowState.pbWindowStateMaximize; publisherApp.ScreenUpdating = true; document.SaveAs(outPath); backWorker.ReportProgress(100); // Release all COM objects Marshal.ReleaseComObject(publisherApp); return(savePath); }