public async Task ExportWordBytesByTemplate_Test()
        {
            var tplPath  = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles", "ExportTemplates", "tpl1.cshtml");
            var tpl      = File.ReadAllText(tplPath);
            var exporter = new WordExporter();
            var ex       = await Assert.ThrowsAnyAsync <ArgumentException>(async() => await exporter.ExportListByTemplate(null,
                                                                                                                          GenFu.GenFu.ListOf <ExportTestData>(), tpl));

            ex.Message.ShouldContain("文件名必须填写");

            var filePath = Path.Combine(Directory.GetCurrentDirectory(), nameof(ExportWordBytesByTemplate_Test) + ".docx");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            //此处使用默认模板导出
            var result = await exporter.ExportListBytesByTemplate(
                GenFu.GenFu.ListOf <ExportTestData>(), tpl);

            result.ShouldNotBeNull();
            using (var file = File.OpenWrite(filePath))
            {
                file.Write(result, 0, result.Length);
            }
            File.Exists(filePath).ShouldBeTrue();
        }
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
            string            tmpFile           = captureDetails.Filename;

            if (tmpFile == null || surface.Modified || !Regex.IsMatch(tmpFile, @".*(\.png|\.gif|\.jpg|\.jpeg|\.tiff|\.bmp)$"))
            {
                tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings().PreventGreenshotFormat());
            }
            if (documentCaption != null)
            {
                try {
                    WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
                    exportInformation.ExportMade = true;
                } catch (Exception) {
                    try {
                        WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
                        exportInformation.ExportMade = true;
                    } catch (Exception ex) {
                        LOG.Error(ex);
                        // TODO: Change to general logic in ProcessExport
                        surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetFormattedString("destination_exportfailed", Description));
                    }
                }
            }
            else
            {
                if (!manuallyInitiated)
                {
                    List <string> documents = WordExporter.GetWordDocuments();
                    if (documents != null && documents.Count > 0)
                    {
                        List <IDestination> destinations = new List <IDestination>();
                        destinations.Add(new WordDestination());
                        foreach (string document in documents)
                        {
                            destinations.Add(new WordDestination(document));
                        }
                        // Return the ExportInformation from the picker without processing, as this indirectly comes from us self
                        return(ShowPickerMenu(false, surface, captureDetails, destinations));
                    }
                }
                try {
                    WordExporter.InsertIntoNewDocument(tmpFile, null, null);
                    exportInformation.ExportMade = true;
                } catch (Exception) {
                    // Retry once, just in case
                    try {
                        WordExporter.InsertIntoNewDocument(tmpFile, null, null);
                        exportInformation.ExportMade = true;
                    } catch (Exception ex) {
                        LOG.Error(ex);
                        // TODO: Change to general logic in ProcessExport
                        surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetFormattedString("destination_exportfailed", Description));
                    }
                }
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
 public override IEnumerable <IDestination> DynamicDestinations()
 {
     foreach (string wordCaption in WordExporter.GetWordDocuments())
     {
         yield return(new WordDestination(wordCaption));
     }
 }
        public async Task ExportWordFileByTemplate_Test()
        {
            var tplPath  = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles", "ExportTemplates", "receipt.cshtml");
            var tpl      = File.ReadAllText(tplPath);
            var exporter = new WordExporter();
            var filePath = Path.Combine(Directory.GetCurrentDirectory(), nameof(ExportWordFileByTemplate_Test) + ".docx");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            //此处使用默认模板导出
            var result = await exporter.ExportByTemplate(filePath,
                                                         new ReceiptInfo
            {
                Amount          = 22939.43M,
                Grade           = "2019秋",
                IdNo            = "43062619890622xxxx",
                Name            = "张三",
                Payee           = "湖南心莱信息科技有限公司",
                PaymentMethod   = "微信支付",
                Profession      = "运动训练",
                Remark          = "学费",
                TradeStatus     = "已完成",
                TradeTime       = DateTime.Now,
                UppercaseAmount = "贰万贰仟玖佰叁拾玖圆肆角叁分",
                Code            = "19071800001"
            }, tpl);

            result.ShouldNotBeNull();
            File.Exists(filePath).ShouldBeTrue();
        }
Example #5
0
        public async Task <bool> HandleSuccessfulReqeustAsync(HttpContext context, object body, Type type, string tplPath)
        {
            var    contentType = "";
            string filename    = DateTime.Now.ToString("yyyyMMddHHmmss");

            byte[] result = null;
            switch (context.Request.Headers["Magicodes-Type"])
            {
            case HttpContentMediaType.XLSXHttpContentMediaType:
                filename += ".xlsx";
                var dt = ToDataTable(body?.ToString());
                contentType = HttpContentMediaType.XLSXHttpContentMediaType;
                var exporter = new ExcelExporter();
                result = await exporter.ExportAsByteArray(dt, type);

                break;

            case HttpContentMediaType.PDFHttpContentMediaType:
                filename   += ".pdf";
                contentType = HttpContentMediaType.PDFHttpContentMediaType;
                IExportFileByTemplate pdfexporter = new PdfExporter();
                var tpl = await File.ReadAllTextAsync(tplPath);

                var obj = JsonConvert.DeserializeObject(body.ToString(), type);
                result = await pdfexporter.ExportBytesByTemplate(obj, tpl, type);

                break;

            case HttpContentMediaType.HTMLHttpContentMediaType:
                filename   += ".html";
                contentType = HttpContentMediaType.HTMLHttpContentMediaType;
                IExportFileByTemplate htmlexporter = new HtmlExporter();
                result = await htmlexporter.ExportBytesByTemplate(JsonConvert.DeserializeObject(body.ToString(), type), await File.ReadAllTextAsync(tplPath), type);

                break;

            case HttpContentMediaType.DOCXHttpContentMediaType:
                filename   += ".docx";
                contentType = HttpContentMediaType.DOCXHttpContentMediaType;
                IExportFileByTemplate docxexporter = new WordExporter();
                result = await docxexporter.ExportBytesByTemplate(JsonConvert.DeserializeObject(body.ToString(), type), await File.ReadAllTextAsync(tplPath), type);

                break;
            }
            if (contentType != "")
            {
                context.Response.Headers.Add("Content-Disposition", $"attachment;filename={filename}");
                context.Response.ContentType = contentType;
                if (result != null)
                {
                    await context.Response.Body.WriteAsync(result, 0, result.Length);
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
Example #6
0
        public void ExportAllRecipes()
        {
            var       repository = DefaultRepositoryHolder.Instance.RecipeRepository;
            IExporter exporter   = new WordExporter();

            foreach (var recipe in repository.GetObjectsQuery())
            {
                exporter.ExportRecipe(recipe);
            }
        }
Example #7
0
        public async Task <bool> HandleSuccessfulReqeustAsync(HttpContext context, object body, IExportData exportData)
        {
            var contentType = "";

            var    fileStr  = !exportData.FileName.IsNullOrWhiteSpace() ? exportData.FileName + "_" : "";
            string filename = fileStr + DateTime.Now.ToString("yyyyMMddHHmmss");

            byte[] result = null;
            switch (context.Request.Headers["exportType"])
            {
            case ExportType.Excel:
                filename += ".xlsx";
                var dt = ToDataTable(body?.ToString());
                contentType = HttpContentMediaType.XLSXHttpContentMediaType;
                var exporter = new ExcelExporter();
                result = await exporter.ExportAsByteArray(dt, exportData.Type);

                break;

            case ExportType.PDF:
                filename   += ".pdf";
                contentType = HttpContentMediaType.PDFHttpContentMediaType;
                IExportFileByTemplate pdfexporter = new PdfExporter();
                var tpl = File.ReadAllText(exportData.TemplatePath);
                var obj = JsonConvert.DeserializeObject(body.ToString(), exportData.Type);
                result = await pdfexporter.ExportBytesByTemplate(obj, tpl, exportData.Type);

                break;

            case ExportType.Word:
                filename   += ".docx";
                contentType = HttpContentMediaType.DOCXHttpContentMediaType;
                IExportFileByTemplate docxexporter = new WordExporter();
                result = await docxexporter.ExportBytesByTemplate(JsonConvert.DeserializeObject(body.ToString(), exportData.Type), File.ReadAllText(exportData.TemplatePath), exportData.Type);

                break;
            }
            if (contentType != "")
            {
                //必须清空原有响应返回内容,否则会抛异常 System.InvalidOperationException: Response Content-Length mismatch: too few bytes written
                context.Response.Clear();
                context.Response.Headers.Add("Content-Disposition", $"attachment;filename={HttpUtility.UrlEncode(filename)}");
                context.Response.ContentType = contentType;
                if (result != null)
                {
                    await context.Response.Body.WriteAsync(result, 0, result.Length);
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
Example #8
0
        public void TryExportWordToPdfUsingLateBindingTest()
        {
            string binPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string source  = binPath + "\\test.docx";
            string target  = binPath + "\\test.pdf";

            string error;

            if (!WordExporter.TryExportToPdf(source, target, false, out error))
            {
                Console.WriteLine(error);
            }

            Assert.IsTrue(File.Exists(target));
        }
        public async Task ExportWord_Test()
        {
            var exporter = new WordExporter();
            var filePath = Path.Combine(Directory.GetCurrentDirectory(), nameof(ExportWord_Test) + ".docx");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            //此处使用默认模板导出
            var result = await exporter.ExportListByTemplate(filePath, GenFu.GenFu.ListOf <ExportTestData>());

            result.ShouldNotBeNull();
            File.Exists(filePath).ShouldBeTrue();
        }
        public async Task ExportWordByTemplate_Test()
        {
            var tplPath  = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles", "ExportTemplates", "tpl1.cshtml");
            var tpl      = File.ReadAllText(tplPath);
            var exporter = new WordExporter();
            var filePath = Path.Combine(Directory.GetCurrentDirectory(), nameof(ExportWordByTemplate_Test) + ".docx");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            //此处使用默认模板导出
            var result = await exporter.ExportByTemplate(filePath,
                                                         GenFu.GenFu.ListOf <ExportTestData>(), tpl);

            result.ShouldNotBeNull();
            File.Exists(filePath).ShouldBeTrue();
        }
Example #11
0
File: Program.cs Project: GAlex7/TA
        public static void Main()
        {
            DataExporter exporter = null;

            // Lets export the data to Excel file
            exporter = new ExcelExporter();
            exporter.ExportFormatedData();

            Console.WriteLine();

            // Lets export the data to PDF file
            exporter = new PDFExporter();
            exporter.ExportFormatedData();

            Console.WriteLine();

            // Lets export the data to Word file
            exporter = new WordExporter();
            exporter.ExportFormatedData();
        }
Example #12
0
File: Program.cs Project: GAlex7/TA
        public static void Main()
        {
            DataExporter exporter = null;

            // Lets export the data to Excel file
            exporter = new ExcelExporter();
            exporter.ExportFormatedData();

            Console.WriteLine();

            // Lets export the data to PDF file
            exporter = new PDFExporter();
            exporter.ExportFormatedData();

            Console.WriteLine();

            // Lets export the data to Word file
            exporter = new WordExporter();
            exporter.ExportFormatedData();
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            string tmpFile = captureDetails.Filename;

            if (tmpFile == null || surface.Modified)
            {
                using (Image image = surface.GetImageForExport()) {
                    tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
                }
            }
            if (documentCaption != null)
            {
                WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
            }
            else
            {
                if (!manuallyInitiated)
                {
                    List <string> documents = WordExporter.GetWordDocuments();
                    if (documents != null && documents.Count > 0)
                    {
                        List <IDestination> destinations = new List <IDestination>();
                        destinations.Add(new WordDestination());
                        foreach (string document in documents)
                        {
                            destinations.Add(new WordDestination(document));
                        }
                        ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
                        PickerDestination.ShowMenuAtCursor(menu);
                        return(false);
                    }
                }
                WordExporter.InsertIntoNewDocument(tmpFile);
            }
            surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            surface.Modified = false;

            return(true);
        }
        private void ExportaDOC(CompanyInfo empresa)
        {
            object oMissing  = System.Reflection.Missing.Value;
            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

            try
            {
                WordExporter.InitWordExporter();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                moleQule.Face.Resources.Labels.ERROR_TITLE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return;
            }

            Word.Document oDoc = WordExporter.NewDocument();

            //Start Word and create a new document.

            /*Word._Application oWord;
             * Word._Document oDoc;
             * oWord = new Word.Application();
             * oWord.Visible = true;
             * oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,
             *  ref oMissing, ref oMissing);*/

            foreach (Word.Section wordSection in oDoc.Sections)
            {
                wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = empresa.Name;
                wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.ShowFirstPageNumber = true;
                wordSection.Range.ParagraphFormat.SpaceAfter  = 0;
                wordSection.Range.ParagraphFormat.SpaceBefore = 0;
            }

            //Márgenes (1cm aprox.)
            oDoc.PageSetup.TopMargin    = 15;
            oDoc.PageSetup.BottomMargin = 0;
            oDoc.PageSetup.LeftMargin   = 30;
            oDoc.PageSetup.RightMargin  = 30;

            //Tabla de encabezado
            Word.Table oTable;
            Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oTable = oDoc.Tables.Add(wrdRng, 5, 4, ref oMissing, ref oMissing);

            oTable.Range.ParagraphFormat.SpaceAfter  = 6;
            oTable.Range.ParagraphFormat.SpaceBefore = 6;

            oTable.Columns[1].Cells.Merge();
            oTable.Borders.Enable           = 1;
            oTable.Borders.InsideLineWidth  = Word.WdLineWidth.wdLineWidth150pt;
            oTable.Borders.OutsideLineWidth = Word.WdLineWidth.wdLineWidth150pt;

            oTable.Columns[2].Cells[1].Merge(oTable.Columns[2].Cells[2]);

            oTable.Columns[1].Width = 108.44F;
            oTable.Columns[3].Width = 81.33F;
            oTable.Columns[4].Width = 81.33F;
            oTable.Columns[2].Width = 271.1F;

            oTable.Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter;

            string logo = CompanyInfo.GetLogoPath(empresa.Oid);

            if (!File.Exists(logo))
            {
                MessageBox.Show("No se ha encontrado la imagen: " + logo);
            }
            else
            {
                oTable.Cell(1, 1).Range.InlineShapes.AddPicture(logo, ref oMissing, ref oMissing, ref oMissing);
            }
            oTable.Cell(1, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;

            ExamenPrint examen = Entity.GetPrintObject(empresa, string.Empty);

            oTable.Cell(1, 2).Range.Text                 = "HOJA DE PREGUNTAS";
            oTable.Cell(1, 2).Range.Font.Bold            = 1;
            oTable.Cell(1, 2).Range.Font.Size            = 16;
            oTable.Cell(1, 2).VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Cell(1, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[2].Cells[1].Range.Font.Name   = "Arial";

            oTable.Columns[2].Cells[2].Range.Text                 = examen.Modulo;
            oTable.Columns[2].Cells[2].Range.Font.Bold            = 1;
            oTable.Columns[2].Cells[2].Range.Font.Size            = 11;
            oTable.Columns[2].Cells[2].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[2].Cells[2].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[2].Cells[2].Range.Font.Name            = "Arial";

            oTable.Columns[2].Cells[3].Range.Text                 = "CURSO : " + examen.Promocion;
            oTable.Columns[2].Cells[3].Range.Font.Bold            = 1;
            oTable.Columns[2].Cells[3].Range.Font.Size            = 11;
            oTable.Columns[2].Cells[3].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[2].Cells[3].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[2].Cells[3].Range.Font.Name            = "Arial";

            oTable.Columns[2].Cells[4].Range.Text                 = "Deberá responder a las preguntas del examen a continuación de las mismas.";
            oTable.Columns[2].Cells[4].Range.Font.Size            = 11;
            oTable.Columns[2].Cells[4].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[2].Cells[4].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[2].Cells[4].Range.Font.Name            = "Arial";

            oTable.Columns[3].Cells[1].Range.Text                 = "Nº EXAMEN";
            oTable.Columns[3].Cells[1].Range.Font.Bold            = 1;
            oTable.Columns[3].Cells[1].Range.Font.Size            = 11;
            oTable.Columns[3].Cells[1].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[3].Cells[1].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[3].Cells[1].Range.Font.Name            = "Arial";

            oTable.Columns[3].Cells[2].Range.Text                 = "FECHA";
            oTable.Columns[3].Cells[2].Range.Font.Bold            = 1;
            oTable.Columns[3].Cells[2].Range.Font.Size            = 11;
            oTable.Columns[3].Cells[2].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[3].Cells[2].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[3].Cells[2].Range.Font.Name            = "Arial";

            oTable.Columns[3].Cells[3].Range.Text                 = "TIPO EXAMEN";
            oTable.Columns[3].Cells[3].Range.Font.Bold            = 1;
            oTable.Columns[3].Cells[3].Range.Font.Size            = 11;
            oTable.Columns[3].Cells[3].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[3].Cells[3].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[3].Cells[3].Range.Font.Name            = "Arial";

            oTable.Columns[3].Cells[4].Range.Text                 = "Nº PREGUNTAS";
            oTable.Columns[3].Cells[4].Range.Font.Bold            = 1;
            oTable.Columns[3].Cells[4].Range.Font.Size            = 11;
            oTable.Columns[3].Cells[4].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[3].Cells[4].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[3].Cells[4].Range.Font.Name            = "Arial";

            oTable.Columns[3].Cells[5].Range.Text                 = "TIEMPO";
            oTable.Columns[3].Cells[5].Range.Font.Bold            = 1;
            oTable.Columns[3].Cells[5].Range.Font.Size            = 11;
            oTable.Columns[3].Cells[5].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[3].Cells[5].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[3].Cells[5].Range.Font.Name            = "Arial";

            oTable.Columns[4].Cells[1].Range.Text                 = examen.Numero.ToString().Trim();
            oTable.Columns[4].Cells[1].Range.Font.Size            = 11;
            oTable.Columns[4].Cells[1].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[4].Cells[1].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[4].Cells[1].Range.Font.Name            = "Arial";

            oTable.Columns[4].Cells[2].Range.Text                 = examen.FechaExamen.ToShortDateString().Trim();
            oTable.Columns[4].Cells[2].Range.Font.Size            = 11;
            oTable.Columns[4].Cells[2].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[4].Cells[2].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[4].Cells[2].Range.Font.Name            = "Arial";

            oTable.Columns[4].Cells[3].Range.Text                 = examen.Tipo.Trim();
            oTable.Columns[4].Cells[3].Range.Font.Size            = 11;
            oTable.Columns[4].Cells[3].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[4].Cells[3].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[4].Cells[3].Range.Font.Name            = "Arial";

            oTable.Columns[4].Cells[4].Range.Text                 = examen.NPreguntas.ToString().Trim();
            oTable.Columns[4].Cells[4].Range.Font.Size            = 11;
            oTable.Columns[4].Cells[4].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[4].Cells[4].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[4].Cells[4].Range.Font.Name            = "Arial";

            oTable.Columns[4].Cells[5].Range.Font.Name            = "Arial";
            oTable.Columns[4].Cells[5].Range.Font.Size            = 11;
            oTable.Columns[4].Cells[5].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            oTable.Columns[4].Cells[5].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            oTable.Columns[4].Cells[5].Range.Text = examen.Duracion.ToShortTimeString().Trim();

            ////Add some text after the table.
            Word.Paragraph oParaAux;
            object         oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            oParaAux            = oDoc.Content.Paragraphs.Add(ref oRng);
            oParaAux.Range.Text = string.Empty;
            oParaAux.Range.InsertParagraph();

            //Nombre y apellidos
            Word.Paragraph oPara1;
            oPara1                 = oDoc.Content.Paragraphs.Add(ref oMissing);
            oPara1.Range.Text      = "NOMBRE Y APELLIDOS:";
            oPara1.Range.Font.Size = 12;
            oPara1.Range.Font.Name = "Arial";
            oPara1.Range.InsertParagraphAfter();
            oPara1.Range.InsertParagraphBefore();

            //DNI/NIE, FIRMA
            Word.Paragraph oPara2;
            oPara2                 = oDoc.Content.Paragraphs.Add(ref oMissing);
            oPara2.Range.Text      = "DNI/NIE:                                                           FIRMA:";
            oPara2.Range.Font.Size = 12;
            oPara2.Range.Font.Name = "Arial";
            oPara2.Range.InsertParagraphAfter();
            oPara2.Range.InsertParagraphBefore();

            PreguntaList lista_preguntas = null;

            //Origen de las preguntas en función de si el examen está emitido o no
            if (_entity.Emitido)
            {
                lista_preguntas = PreguntaList.GetList(_entity.PreguntaExamenes);
            }
            else
            {
                lista_preguntas = _preguntas;
            }

            if (lista_preguntas != null)
            {
                int          i = 1;
                PreguntaInfo item;

                foreach (PreguntaExamenInfo pex in _entity.PreguntaExamenes)
                {
                    item = lista_preguntas.GetItem(pex.OidPregunta);

                    /*if (_preguntas_examen != null)
                     * {
                     *  int i = 1;
                     *
                     *  foreach (Pregunta_Examen preg in _preguntas_examen)
                     *  {
                     *      Pregunta item = _preguntas.GetItem(preg.OidPregunta);*/

                    //Para cada pregunta se inserta una tabla
                    wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    Word.Range newRng        = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    int        paginas_antes = (int)(oTable.Range.get_Information(Word.WdInformation.wdNumberOfPagesInDocument));
                    oTable = oDoc.Tables.Add(wrdRng, 2, 3, ref oMissing, ref oMissing);

                    oTable.Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAuto;

                    oTable.Columns[1].Width                      = 30;
                    oTable.Cell(1, 1).Range.Text                 = i.ToString();
                    oTable.Cell(1, 1).Range.Font.Size            = 10;
                    oTable.Cell(1, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    oTable.Cell(1, 1).Range.Font.Bold            = 1;
                    oTable.Cell(1, 1).Range.Font.Name            = "Arial";

                    oTable.Cell(1, 2).Merge(oTable.Columns[3].Cells[1]);
                    oTable.Cell(1, 2).Width                      = 510;
                    oTable.Cell(1, 2).Range.Text                 = item.Texto;
                    oTable.Cell(1, 2).Range.Font.Size            = 10;
                    oTable.Cell(1, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify;
                    oTable.Cell(1, 2).Range.Font.Bold            = 1;
                    oTable.Cell(1, 2).Range.Font.Name            = "Arial";

                    oTable.Cell(2, 2).Merge(oTable.Cell(2, 3));
                    oTable.Cell(2, 1).Merge(oTable.Cell(2, 2));
                    oTable.Cell(2, 1).Width = 540;

                    if (item.Imagen != string.Empty)
                    {
                        string path = item.ImagenWithPath;

                        if (File.Exists(path))
                        {
                            oTable.Cell(2, 1).Range.InlineShapes.AddPictureBullet(path, ref oMissing);
                            oTable.Cell(2, 1).VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                            oTable.Cell(2, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        }
                        else
                        {
                            oTable.Rows[2].Delete();
                        }
                    }
                    else
                    {
                        oTable.Rows[2].Delete();
                    }

                    ////Add some text after the table.
                    oRng                = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    oParaAux            = oDoc.Content.Paragraphs.Add(ref oRng);
                    oParaAux.Range.Text = string.Empty;
                    oParaAux.Range.InsertParagraph();

                    int paginas_despues = (int)(oParaAux.Range.get_Information(Word.WdInformation.wdNumberOfPagesInDocument));
                    if (paginas_antes < paginas_despues)
                    {
                        newRng.InsertBreak(ref oMissing);
                    }

                    i++;
                }
            }
            else
            {
                foreach (PreguntaExamenInfo item in Entity.PreguntaExamenes)
                {
                    //Para cada pregunta se inserta una tabla
                    wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    Word.Range newRng        = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    int        paginas_antes = (int)(oTable.Range.get_Information(Word.WdInformation.wdNumberOfPagesInDocument));
                    oTable = oDoc.Tables.Add(wrdRng, 2, 3, ref oMissing, ref oMissing);

                    oTable.Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAuto;

                    oTable.Columns[1].Width                      = 30;
                    oTable.Cell(1, 1).Range.Text                 = item.Orden.ToString();
                    oTable.Cell(1, 1).Range.Font.Size            = 10;
                    oTable.Cell(1, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    oTable.Cell(1, 1).Range.Font.Bold            = 1;
                    oTable.Cell(1, 1).Range.Font.Name            = "Arial";

                    oTable.Cell(1, 2).Merge(oTable.Columns[3].Cells[1]);
                    oTable.Cell(1, 2).Width                      = 510;
                    oTable.Cell(1, 2).Range.Text                 = item.Texto;
                    oTable.Cell(1, 2).Range.Font.Size            = 10;
                    oTable.Cell(1, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify;
                    oTable.Cell(1, 2).Range.Font.Bold            = 1;
                    oTable.Cell(1, 2).Range.Font.Name            = "Arial";

                    oTable.Cell(2, 2).Merge(oTable.Cell(2, 3));
                    oTable.Cell(2, 1).Merge(oTable.Cell(2, 2));
                    oTable.Cell(2, 1).Width = 540;

                    if (item.Imagen != string.Empty)
                    {
                        /*string path = Images.GetRootPath() + PreguntaExamenInfo.GetImagenesPath() +
                         *  item.OidExamen.ToString("00000") + "\\" + item.Imagen;*/
                        string path = item.ImagenWithPath;

                        if (File.Exists(path))
                        {
                            oTable.Cell(2, 1).Range.InlineShapes.AddPictureBullet(path, ref oMissing);
                            oTable.Cell(2, 1).VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                            oTable.Cell(2, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        }
                        else
                        {
                            oTable.Rows[2].Delete();
                        }
                    }
                    else
                    {
                        oTable.Rows[2].Delete();
                    }

                    ////Add some text after the table.
                    oRng                = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                    oParaAux            = oDoc.Content.Paragraphs.Add(ref oRng);
                    oParaAux.Range.Text = string.Empty;
                    oParaAux.Range.InsertParagraph();

                    int paginas_despues = (int)(oParaAux.Range.get_Information(Word.WdInformation.wdNumberOfPagesInDocument));
                    if (paginas_antes < paginas_despues)
                    {
                        newRng.InsertBreak(ref oMissing);
                    }
                }
            }

            WordExporter.Close();
        }
Example #15
0
 public override IEnumerable <IDestination> DynamicDestinations()
 {
     return(WordExporter.GetWordDocuments().Select(wordCaption => new WordDestination(wordCaption, CoreConfiguration, GreenshotLanguage)));
 }
Example #16
0
        public async Task HandleSuccessfulReqeustAsync(HttpContext context, object body, Type type, string tplPath)
        {
            var    contentType = "";
            string filename    = DateTime.Now.ToString("yyyyMMddHHmmss");

            byte[] result = null;
            switch (context.Request.ContentType)
            {
            case HttpContentMediaType.XLSXHttpContentMediaType:
                filename += ".xlsx";
                var dt = ToDataTable(body?.ToString());
                contentType = HttpContentMediaType.XLSXHttpContentMediaType;
                var exporter = new ExcelExporter();
                result = await exporter.ExportAsByteArray(dt, type);

                break;

            case HttpContentMediaType.PDFHttpContentMediaType:
                filename   += ".pdf";
                contentType = HttpContentMediaType.PDFHttpContentMediaType;
                IExportFileByTemplate pdfexporter = new PdfExporter();
                tplPath = Path.Combine(Directory.GetCurrentDirectory(), "ExportTemplates",
                                       "batchReceipt.cshtml");
                var tpl = File.ReadAllText(tplPath);
                var obj = JsonConvert.DeserializeObject(body.ToString(), type);
                result = await pdfexporter.ExportBytesByTemplate(obj, tpl, type);

                break;

            case HttpContentMediaType.HTMLHttpContentMediaType:
                filename   += ".html";
                contentType = HttpContentMediaType.HTMLHttpContentMediaType;
                IExportFileByTemplate htmlexporter = new HtmlExporter();
                result = await htmlexporter.ExportBytesByTemplate(JsonConvert.DeserializeObject(body.ToString(), type), File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "ExportTemplates",
                                                                                                                                                      "receipt.cshtml")), type);

                break;

            case HttpContentMediaType.DOCXHttpContentMediaType:
                filename += ".docx";
                IExportFileByTemplate docxexporter = new WordExporter();
                result = await docxexporter.ExportBytesByTemplate(JsonConvert.DeserializeObject(body.ToString(), type), File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "ExportTemplates",
                                                                                                                                                      "receipt.cshtml")), type);

                break;

            default:
                break;
            }

            #region  excel
            //var dt = ToDataTable(body?.ToString());
            ////Excel
            //IExporter exporter = new ExcelExporter();
            //var result = await exporter.ExportAsByteArray(dt, type);
            //context.Response.Headers.Add("Content-Disposition", "attachment;filename=test.xlsx");
            //context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8";
            #endregion

            #region PDF
            //IExportFileByTemplate exporter = new PdfExporter();
            //var tplPath = Path.Combine(Directory.GetCurrentDirectory(), "ExportTemplates",
            //    "batchReceipt.cshtml");
            //var tpl = File.ReadAllText(tplPath);
            //var obj = JsonConvert.DeserializeObject(body.ToString(), type);
            //var result = await exporter.ExportBytesByTemplate(obj, tpl, type);
            //context.Response.Headers.Add("Content-Disposition", "attachment;filename=test.pdf");
            //context.Response.ContentType = "application/pdf; charset=UTF-8";
            #endregion

            #region HTML
            //IExportFileByTemplate exporter = new HtmlExporter();
            //var tplPath = Path.Combine(Directory.GetCurrentDirectory(), "ExportTemplates",
            //    "receipt.cshtml");
            //var tpl = File.ReadAllText(tplPath);
            //var obj = JsonConvert.DeserializeObject(body.ToString(), type);
            //var result = await exporter.ExportBytesByTemplate(obj, tpl, type);
            //context.Response.Headers.Add("Content-Disposition", "attachment;filename=test.html");
            //context.Response.ContentType = "text/html; charset=UTF-8";
            #endregion

            #region Word
            //IExportFileByTemplate exporter = new WordExporter();
            //var tplPath = Path.Combine(Directory.GetCurrentDirectory(), "ExportTemplates",
            //    "receipt.cshtml");
            //var tpl = File.ReadAllText(tplPath);
            //var obj = JsonConvert.DeserializeObject(body.ToString(), type);
            //var result = await exporter.ExportBytesByTemplate(obj, tpl, type);
            //context.Response.Headers.Add("Content-Disposition", "attachment;filename=test.docx");
            //context.Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";

            #endregion

            context.Response.Headers.Add("Content-Disposition", $"attachment;filename={filename}");
            context.Response.ContentType = contentType;
            await context.Response.Body.WriteAsync(result, 0, result.Length);
        }
Example #17
0
		public override IEnumerable<IDestination> DynamicDestinations()
		{
			return WordExporter.GetWordDocuments().Select(wordCaption => new WordDestination(wordCaption));
		}
        private void ExportaDOC(CompanyInfo empresa)
        {
            object      oMissing  = System.Reflection.Missing.Value;
            object      oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
            ExamenPrint examen    = null;

            try
            {
                WordExporter.InitWordExporter();

                examen = Entity.GetPrintObject(empresa, string.Empty);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                moleQule.Face.Resources.Labels.ERROR_TITLE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            PgMng.Reset(_entity.PreguntaExamenes.Count + 7, 1, Resources.Messages.LOADING_DATA, this);

            try
            {
                Word.Document oDoc = WordExporter.NewDocument();
                PgMng.Grow();

                foreach (Word.Section wordSection in oDoc.Sections)
                {
                    wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
                    .Range.Text = empresa.Name;
                    wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
                    .Range.Borders.DistanceFromTop = 10;
                    wordSection.Footers[
                        Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.ShowFirstPageNumber = true;
                    wordSection.Range.ParagraphFormat.SpaceAfter  = 0;
                    wordSection.Range.ParagraphFormat.SpaceBefore = 0;
                }
                PgMng.Grow();

                //Márgenes (1cm aprox.)
                oDoc.PageSetup.TopMargin    = 15;
                oDoc.PageSetup.BottomMargin = 0;
                oDoc.PageSetup.LeftMargin   = 30;
                oDoc.PageSetup.RightMargin  = 30;

                //Tabla de encabezado
                Word.Table oTable;
                Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                oTable = oDoc.Tables.Add(wrdRng, 5, 4, ref oMissing, ref oMissing);

                oTable.Range.ParagraphFormat.SpaceAfter  = 6;
                oTable.Range.ParagraphFormat.SpaceBefore = 6;

                oTable.Columns[1].Cells.Merge();
                oTable.Borders.Enable           = 1;
                oTable.Borders.InsideLineWidth  = Word.WdLineWidth.wdLineWidth150pt;
                oTable.Borders.OutsideLineWidth = Word.WdLineWidth.wdLineWidth150pt;

                oTable.Columns[2].Cells[1].Merge(oTable.Columns[2].Cells[2]);

                oTable.Columns[1].Width = 108.44F;
                oTable.Columns[3].Width = 81.33F;
                oTable.Columns[4].Width = 81.33F;
                oTable.Columns[2].Width = 271.1F;

                oTable.Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter;
                PgMng.Grow();

                string logo = CompanyInfo.GetLogoPath(empresa.Oid);
                if (!File.Exists(logo))
                {
                    MessageBox.Show("No se ha encontrado la imagen: " + logo);
                }
                else
                {
                    oTable.Cell(1, 1).Range.InlineShapes.AddPicture(logo, ref oMissing, ref oMissing, ref oMissing);
                }
                oTable.Cell(1, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                PgMng.Grow();

                oTable.Cell(1, 2).Range.Text                 = "HOJA DE PREGUNTAS";
                oTable.Cell(1, 2).Range.Font.Bold            = 1;
                oTable.Cell(1, 2).Range.Font.Size            = 16;
                oTable.Cell(1, 2).VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Cell(1, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[2].Cells[1].Range.Font.Name   = "Arial";

                oTable.Columns[2].Cells[2].Range.Text                 = examen.Modulo;
                oTable.Columns[2].Cells[2].Range.Font.Bold            = 1;
                oTable.Columns[2].Cells[2].Range.Font.Size            = 11;
                oTable.Columns[2].Cells[2].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[2].Cells[2].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[2].Cells[2].Range.Font.Name            = "Arial";

                oTable.Columns[2].Cells[3].Range.Text                 = "CURSO : " + examen.Promocion;
                oTable.Columns[2].Cells[3].Range.Font.Bold            = 1;
                oTable.Columns[2].Cells[3].Range.Font.Size            = 11;
                oTable.Columns[2].Cells[3].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[2].Cells[3].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[2].Cells[3].Range.Font.Name            = "Arial";

                oTable.Columns[2].Cells[4].Range.Text =
                    "Deberá utilizar la plantilla que se le entregará para responder a las preguntas del examen.";
                oTable.Columns[2].Cells[4].Range.Font.Size            = 11;
                oTable.Columns[2].Cells[4].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[2].Cells[4].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[2].Cells[4].Range.Font.Name            = "Arial";

                oTable.Columns[3].Cells[1].Range.Text                 = "Nº EXAMEN";
                oTable.Columns[3].Cells[1].Range.Font.Bold            = 1;
                oTable.Columns[3].Cells[1].Range.Font.Size            = 11;
                oTable.Columns[3].Cells[1].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[3].Cells[1].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[3].Cells[1].Range.Font.Name            = "Arial";

                oTable.Columns[3].Cells[2].Range.Text                 = "FECHA";
                oTable.Columns[3].Cells[2].Range.Font.Bold            = 1;
                oTable.Columns[3].Cells[2].Range.Font.Size            = 11;
                oTable.Columns[3].Cells[2].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[3].Cells[2].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[3].Cells[2].Range.Font.Name            = "Arial";

                oTable.Columns[3].Cells[3].Range.Text                 = "TIPO EXAMEN";
                oTable.Columns[3].Cells[3].Range.Font.Bold            = 1;
                oTable.Columns[3].Cells[3].Range.Font.Size            = 11;
                oTable.Columns[3].Cells[3].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[3].Cells[3].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[3].Cells[3].Range.Font.Name            = "Arial";

                oTable.Columns[3].Cells[4].Range.Text                 = "Nº PREGUNTAS";
                oTable.Columns[3].Cells[4].Range.Font.Bold            = 1;
                oTable.Columns[3].Cells[4].Range.Font.Size            = 11;
                oTable.Columns[3].Cells[4].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[3].Cells[4].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[3].Cells[4].Range.Font.Name            = "Arial";

                oTable.Columns[3].Cells[5].Range.Text                 = "TIEMPO";
                oTable.Columns[3].Cells[5].Range.Font.Bold            = 1;
                oTable.Columns[3].Cells[5].Range.Font.Size            = 11;
                oTable.Columns[3].Cells[5].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[3].Cells[5].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[3].Cells[5].Range.Font.Name            = "Arial";

                oTable.Columns[4].Cells[1].Range.Text                 = examen.Numero.ToString().Trim();
                oTable.Columns[4].Cells[1].Range.Font.Size            = 11;
                oTable.Columns[4].Cells[1].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[4].Cells[1].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[4].Cells[1].Range.Font.Name            = "Arial";

                oTable.Columns[4].Cells[2].Range.Text                 = examen.FechaExamen.ToShortDateString().Trim();
                oTable.Columns[4].Cells[2].Range.Font.Size            = 11;
                oTable.Columns[4].Cells[2].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[4].Cells[2].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[4].Cells[2].Range.Font.Name            = "Arial";

                oTable.Columns[4].Cells[3].Range.Text                 = examen.Tipo.Trim();
                oTable.Columns[4].Cells[3].Range.Font.Size            = 11;
                oTable.Columns[4].Cells[3].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[4].Cells[3].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[4].Cells[3].Range.Font.Name            = "Arial";

                oTable.Columns[4].Cells[4].Range.Text                 = examen.NPreguntas.ToString().Trim();
                oTable.Columns[4].Cells[4].Range.Font.Size            = 11;
                oTable.Columns[4].Cells[4].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[4].Cells[4].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[4].Cells[4].Range.Font.Name            = "Arial";

                oTable.Columns[4].Cells[5].Range.Font.Name            = "Arial";
                oTable.Columns[4].Cells[5].Range.Font.Size            = 11;
                oTable.Columns[4].Cells[5].VerticalAlignment          = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                oTable.Columns[4].Cells[5].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                oTable.Columns[4].Cells[5].Range.Text = examen.Duracion.ToShortTimeString().Trim();
                PgMng.Grow();

                ////Add some text after the table.
                Word.Paragraph oParaAux;
                object         oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                oParaAux            = oDoc.Content.Paragraphs.Add(ref oRng);
                oParaAux.Range.Text = string.Empty;
                oParaAux.Range.InsertParagraph();

                //Nombre y apellidos
                Word.Paragraph oPara1;
                oPara1                 = oDoc.Content.Paragraphs.Add(ref oMissing);
                oPara1.Range.Text      = "NOMBRE Y APELLIDOS:";
                oPara1.Range.Font.Size = 12;
                oPara1.Range.Font.Name = "Arial";
                oPara1.Range.InsertParagraphAfter();
                oPara1.Range.InsertParagraphBefore();

                //DNI/NIE, FIRMA
                Word.Paragraph oPara2;
                oPara2                 = oDoc.Content.Paragraphs.Add(ref oMissing);
                oPara2.Range.Text      = "DNI/NIE:                                                           FIRMA:";
                oPara2.Range.Font.Size = 12;
                oPara2.Range.Font.Name = "Arial";
                oPara2.Range.InsertParagraphAfter();
                oPara2.Range.InsertParagraphBefore();
                PgMng.Grow();

                PreguntaList lista_preguntas = null;

                //Origen de las preguntas en función de si el examen está emitido o no
                if (_entity.Emitido)
                {
                    lista_preguntas = PreguntaList.GetList(_entity.PreguntaExamenes);
                }
                else
                {
                    lista_preguntas = _preguntas;
                }

                if (lista_preguntas != null)
                {
                    int          i = 1;
                    PreguntaInfo item;

                    foreach (PreguntaExamenInfo pex in _entity.PreguntaExamenes)
                    {
                        item = lista_preguntas.GetItem(pex.OidPregunta);

                        //Para cada pregunta se inserta una tabla
                        wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                        Word.Range newRng        = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                        int        paginas_antes = (int)(oTable.Range.get_Information(
                                                             Word.WdInformation.wdNumberOfPagesInDocument));
                        oTable = oDoc.Tables.Add(wrdRng, 5, 3, ref oMissing, ref oMissing);

                        oTable.Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAuto;

                        oTable.Columns[1].Width                      = 30;
                        oTable.Cell(1, 1).Range.Text                 = i.ToString();
                        oTable.Cell(1, 1).Range.Font.Size            = 10;
                        oTable.Cell(1, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        oTable.Cell(1, 1).Range.Font.Bold            = 1;
                        oTable.Cell(1, 1).Range.Font.Name            = "Arial";

                        oTable.Cell(1, 2).Merge(oTable.Columns[3].Cells[1]);
                        oTable.Cell(1, 2).BottomPadding              = 8;
                        oTable.Cell(1, 2).Width                      = 510;
                        oTable.Cell(1, 2).Range.Text                 = item.Texto;
                        oTable.Cell(1, 2).Range.Font.Size            = 10;
                        oTable.Cell(1, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify;
                        oTable.Cell(1, 2).Range.Font.Bold            = 1;
                        oTable.Cell(1, 2).Range.Font.Name            = "Arial";

                        oTable.Cell(2, 2).Merge(oTable.Cell(2, 3));
                        oTable.Cell(2, 1).Merge(oTable.Cell(2, 2));
                        oTable.Cell(2, 1).Width = 540;

                        oTable.Cell(3, 2).Width                      = 20;
                        oTable.Cell(3, 2).Range.Text                 = "A";
                        oTable.Cell(3, 2).Range.Font.Size            = 10;
                        oTable.Cell(3, 2).Range.Paragraphs.Alignment =
                            Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        oTable.Cell(3, 2).Range.Font.Name = "Arial";

                        oTable.Cell(4, 2).Width                      = 20;
                        oTable.Cell(4, 2).Range.Text                 = "B";
                        oTable.Cell(4, 2).Range.Font.Size            = 10;
                        oTable.Cell(4, 2).Range.Paragraphs.Alignment =
                            Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        oTable.Cell(4, 2).Range.Font.Name = "Arial";

                        oTable.Cell(5, 2).Width                      = 20;
                        oTable.Cell(5, 2).Range.Text                 = "C";
                        oTable.Cell(5, 2).Range.Font.Size            = 10;
                        oTable.Cell(5, 2).Range.Paragraphs.Alignment =
                            Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        oTable.Cell(5, 2).Range.Font.Name = "Arial";

                        foreach (RespuestaInfo obj in item.Respuestas)
                        {
                            switch (obj.Opcion)
                            {
                            case "A":
                            {
                                oTable.Cell(3, 3).Width                      = 490;
                                oTable.Cell(3, 3).Range.Text                 = obj.Texto;
                                oTable.Cell(3, 3).Range.Font.Size            = 10;
                                oTable.Cell(3, 3).Range.Paragraphs.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphJustify;
                                oTable.Cell(3, 3).Range.Font.Name = "Arial";
                                break;
                            }

                            case "B":
                            {
                                oTable.Cell(4, 3).Width                      = 490;
                                oTable.Cell(4, 3).Range.Text                 = obj.Texto;
                                oTable.Cell(4, 3).Range.Font.Size            = 10;
                                oTable.Cell(4, 3).Range.Paragraphs.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphJustify;
                                oTable.Cell(4, 3).Range.Font.Name = "Arial";
                                break;
                            }

                            case "C":
                            {
                                oTable.Cell(5, 3).Width                      = 490;
                                oTable.Cell(5, 3).Range.Text                 = obj.Texto;
                                oTable.Cell(5, 3).Range.Font.Size            = 10;
                                oTable.Cell(5, 3).Range.Paragraphs.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphJustify;
                                oTable.Cell(5, 3).Range.Font.Name = "Arial";
                                break;
                            }
                            }
                        }

                        if (item.Imagen != string.Empty)
                        {
                            string path = _entity.Emitido ?
                                          Library.Application.AppController.FOTOS_PREGUNTAS_EXAMEN_PATH + _entity.Oid.ToString("00000") + "\\" + item.Imagen :
                                          item.ImagenWithPath;

                            if (File.Exists(path))
                            {
                                oTable.Cell(2, 1).Range.InlineShapes.AddPictureBullet(path, ref oMissing);
                                oTable.Cell(2, 1).VerticalAlignment =
                                    Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                oTable.Cell(2, 1).Range.Paragraphs.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter;
                            }
                            else
                            {
                                MessageBox.Show("No se ha encontrado la imagen: " + path);
                                oTable.Rows[2].Delete();
                            }
                        }
                        else
                        {
                            oTable.Rows[2].Delete();
                        }

                        ////Add some text after the table.
                        oRng                = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
                        oParaAux            = oDoc.Content.Paragraphs.Add(ref oRng);
                        oParaAux.Range.Text = string.Empty;
                        oParaAux.Range.InsertParagraph();

                        int paginas_despues = (int)(oParaAux.Range.get_Information(
                                                        Word.WdInformation.wdNumberOfPagesInDocument));
                        if (paginas_antes < paginas_despues)
                        {
                            newRng.InsertBreak(ref oMissing);
                        }

                        i++;
                    }
                    PgMng.Grow();
                    oDoc.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdPromptToSaveChanges,
                               Microsoft.Office.Interop.Word.WdOriginalFormat.wdPromptUser,
                               true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                moleQule.Face.Resources.Labels.ERROR_TITLE,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            finally
            {
                WordExporter.Close();
                PgMng.FillUp();
            }
        }