Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void GeneratePDFxls()
- {
- Excel.Application xlApp;
- Excel.Workbook xlWorkBook;
- Excel.Worksheet xlWorkSheet;
- object misValue = System.Reflection.Missing.Value;
- xlApp = new Excel.Application();
- xlApp.Visible = true;
- xlWorkBook = xlApp.Workbooks.Open(@"C:\temp\testb.xls");
- xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
- PDF.clsPDFCreator creator = new PDF.clsPDFCreator();
- string parameters = "/NoProcessingAtStartup";
- if (!creator.cStart(parameters, false))
- {
- Console.WriteLine("Unable to start PDFCreator.");
- }
- creator.cOptions.UseAutosave = 1;
- creator.cOptions.UseAutosaveDirectory = 1;
- creator.cOptions.AutosaveDirectory = xlWorkBook.Path ;
- creator.cOptions.AutosaveFilename = xlWorkSheet.Name;
- creator.cOptions.AutosaveFormat = 0;
- creator.cClearCache();
- xlWorkSheet.PrintOut(Type.Missing, Type.Missing, 1, true, "PDFCreator", false, false, Type.Missing);
- while (creator.cCountOfPrintjobs != 1)
- {
- Application.DoEvents();
- System.Threading.Thread.Sleep(1000);
- }
- creator.cPrinterStop = false;
- while (creator.cCountOfPrintjobs != 0)
- {
- Application.DoEvents();
- System.Threading.Thread.Sleep(1000);
- }
- creator.cPrinterStop = true;
- creator.cClose();
- creator = null;
- xlWorkBook.Close(true, misValue, misValue);
- xlApp.Quit();
- releaseObject(xlWorkSheet);
- releaseObject(xlWorkBook);
- releaseObject(xlApp);
- }
Advertisement
Add Comment
Please, Sign In to add comment