//ExStart
//ExId:XpsPrint_PrintDocument
//ExSummary:Convert an Aspose.Words document into an XPS stream and print.
        /// <summary>
        /// Sends an Aspose.Words document to a printer using the XpsPrint API.
        /// </summary>
        /// <param name="document"></param>
        /// <param name="printerName"></param>
        /// <param name="jobName">Job name. Can be null.</param>
        /// <param name="isWait">True to wait for the job to complete. False to return immediately after submitting the job.</param>
        /// <exception cref="Exception">Thrown if any error occurs.</exception>
        public static void Print(Aspose.Words.Document document, string printerName, string jobName, bool isWait)
        {
            if (document == null)
                throw new ArgumentNullException("document");

            // Use Aspose.Words to convert the document to XPS and store in a memory stream.
            MemoryStream stream = new MemoryStream();
            document.Save(stream, Aspose.Words.SaveFormat.Xps);
            stream.Position = 0;

            Print(stream, printerName, jobName, isWait);
        }
示例#2
0
        /// <summary>
        /// 儲存 Excel 報表。
        /// </summary>
        /// <param name="workbook">要儲存的報表物件</param>
        /// <param name="filename">儲存的檔案名稱</param>
        public static void SaveWorkbook(Aspose.Cells.Workbook workbook, string filename)
        {
            string path = CreatePath(filename, ".xls");

            try
            {
                workbook.Save(path);
                OpenFile(path, path);
            }
            catch (Exception ex)
            {
                //MsgBox.Show("儲存失敗" + ex.Message);
            }
        }
        /// <summary>
        /// 目前僅支援 Aspose.Cells 報表。
        /// </summary>
        /// <param name="document">要儲存的報表物件。</param>
        /// <param name="fileFullName">儲存的檔案名稱,請記得加入副檔名(.xls)。</param>
        /// <param name="openAfterSave">產生完報表是否由程式開啟。批次產生報表時,務必傳入 false。</param>
        /// <param name="type">目前僅支援 DocumentType.HSSFWorkbook,未來將支援 DocumentType.PDF。</param>
        public static void Save(Aspose.Cells.Workbook document, string fileFullName, bool openAfterSave, DocumentType type)
        {
            try
            {
                document.Save(fileFullName);

                if (openAfterSave)
                    Open(fileFullName);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
 //METHODS
 //method for saving document
 private static void saveDoc(Aspose.Words.Document document, string outputFile)
 {
     try
     {
         document.Save(outputFile);
         writeToLog("Temporary document saved " + outputFile.ToString());
     }
     catch (Exception e)
     {
         Console.WriteLine("Application PDBOT failed with error: " + e.StackTrace);
         writeToLog("Error saving temporary document " + e.StackTrace);
         Console.ReadKey();
     }
     finally
     {
         document = null;
     }
 }