he creado un servicio que convierte archivos excel a PDF. La función que me los imprime es la siguiente:
Código:
Si hago pruebas para generar el informe, se abre el archivo excel y te aparece el típico mensaje de "¿Desea guardar los cambios efectuados en ....?". He de decir que el excel se genera a partir de una plantilla. En este punto se queda colgado el servicio y no hay manera de que prosiga con su ejecución. ¿Alguién sabe como hacer para que se acepte o se cancele dinámicamente este mensaje?/// <summary> /// Genera un .PDF con la página actual del archivo .xls /// </summary> /// <param name="sFicheroXLS">Ruta al archivo .xls</param> /// <param name="sDirectorio">Directorio del fichero de salida</param> /// <param name="sFicheroPDF">Nombre del fichero SIN EXTENSIÓN NI PUNTOS</param> private bool PrintIt(String sFicheroXLS, String sDirectorio, String sFicheroPDF) { try { bool bResultado = true; string DefaultPrinter; FileInfo fi; PDFCreator.clsPDFCreatorOptions opt; fi = new FileInfo(sFicheroXLS); if (fi.Name.Length > 0) { CLogger.MsgDebug("Comprobando archivo a imprimir"); if (!_PDFCreator.cIsPrintable(fi.FullName)) { CLogger.MsgDebug("File '" + fi.FullName + "' is not printable!"); return false; } opt = _PDFCreator.cOptions; opt.UseAutosave = 1; opt.UseAutosaveDirectory = 1; opt.AutosaveDirectory = sDirectorio; opt.AutosaveFormat = 0; opt.AutosaveFilename = sFicheroPDF; _PDFCreator.cOptions = opt; _PDFCreator.cClearCache(); DefaultPrinter = _PDFCreator.cDefaultPrinter; _PDFCreator.cDefaultPrinter = "PDFCreator"; oTimeOut.Interval = 120 * 1000; oTimeOut.Enabled = true; CLogger.MsgDebug("CPrintFile: " + fi.FullName); _PDFCreator.cPrintFile(fi.FullName); ReadyState = false; _PDFCreator.cPrinterStop = false; CLogger.MsgDebug("Espera máxima: " + oTimeOut.Interval.ToString()); while (!ReadyState && oTimeOut.Enabled) { // Esperamos a que termine de imprimir // o a que salte el timer } CLogger.MsgDebug("HA TERMINADO DE IMPRIMIR"); oTimeOut.Enabled = false; if (!ReadyState) { bResultado = false; CLogger.MsgError("\nSE EXCEDIÓ EL TIEMPO DE IMPRESIÓN\n"); } //_PDFCreator.cCombineAll(); _PDFCreator.cPrinterStop = true; _PDFCreator.cDefaultPrinter = DefaultPrinter; _PDFCreator.cClose(); System.Runtime.InteropServices.Marshal.ReleaseComObject(_PDFCreator); System.Runtime.InteropServices.Marshal.ReleaseComObject(pErr); pErr = null; GC.Collect(); GC.WaitForPendingFinalizers(); return bResultado; } else return false; } catch (Exception e){ CLogger.MsgError("ERROR AL ELIMINAR PDFCREATOR", e); if (_PDFCreator != null) _PDFCreator = null; GC.Collect(); GC.WaitForPendingFinalizers(); return false; } }
Muchas gracias