From a88b76cc670734aeb94eb351998e525365aed7eb Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 2 Jun 2026 20:01:45 +0200 Subject: [PATCH] 02/06/2026 V 5.0.9 Se cambia sobrecarga de CombinaDocx a una nueva funcion CombinaDocxPdfPorBloques --- Baget/Aplicacion.nuspec | 2 +- My Project/AssemblyInfo.vb | 8 +++- Utilidades/Docx.vb | 75 +++++++++++++++----------------------- 3 files changed, 37 insertions(+), 48 deletions(-) diff --git a/Baget/Aplicacion.nuspec b/Baget/Aplicacion.nuspec index 77b7311..81be2f7 100644 --- a/Baget/Aplicacion.nuspec +++ b/Baget/Aplicacion.nuspec @@ -2,7 +2,7 @@ tsWPF - 5.0.8.0 + 5.0.9.0 Tecnosis Tecnosis false diff --git a/My Project/AssemblyInfo.vb b/My Project/AssemblyInfo.vb index e2ab004..44bf2fb 100644 --- a/My Project/AssemblyInfo.vb +++ b/My Project/AssemblyInfo.vb @@ -55,10 +55,14 @@ Imports System.Windows ' mediante el asterisco ('*'), como se muestra a continuación: ' - - + + +' Cambios en la versión 5.0.9.0 + +' 02/06/2026 V 5.0.9 Se cambia sobrecarga de CombinaDocx a una nueva funcion CombinaDocxPdfPorBloques + ' Cambios en la versión 5.0.8.0 ' 02/06/2026 V 5.0.8 Se añade parametro opcional a docx.combinar diff --git a/Utilidades/Docx.vb b/Utilidades/Docx.vb index 951bf52..e6c7580 100644 --- a/Utilidades/Docx.vb +++ b/Utilidades/Docx.vb @@ -29,53 +29,38 @@ Namespace Utilidades Throw New Exception(ex.Message, ex) End Try End Function - Public Shared Function CombinaDocx(tabla As DataTable, Plantilla() As Byte, FormatoPDF As Boolean, Optional NumRegBloque As Integer = 1000, Optional manejadorCalculateVariable As CalculateDocumentVariableEventHandler = Nothing) As Byte() + Public Shared Function CombinaDocxPdfPorBloques(tabla As DataTable, Plantilla() As Byte, NumRegBloque As Integer, Optional manejadorCalculateVariable As CalculateDocumentVariableEventHandler = Nothing) As Byte() Try - - If FormatoPDF Then - ' Throw New Exception("Exportación a pdf aún no soportada") - Dim iNumBloques As Integer = (Int((tabla.Rows.Count - 1) / NumRegBloque)) - 1 - If tabla.Rows.Count Mod NumRegBloque > 1 Then iNumBloques += 1 - Dim sp(iNumBloques) As String - Dim sd(iNumBloques) As String - Dim p As New IO.MemoryStream(Plantilla) - Dim iRegIni As Integer - Dim iRegFin As Integer - For i = 0 To iNumBloques - sd(i) = tsl5.Utilidades.ObtieneFicheroAleatorio("docx") - sp(i) = tsl5.Utilidades.ObtieneFicheroAleatorio("pdf") - Dim fs As New IO.FileStream(sd(i), IO.FileMode.CreateNew, IO.FileAccess.Write) - iRegIni = i * NumRegBloque - iRegFin = Math.Min((i * NumRegBloque) + NumRegBloque - 1, tabla.Rows.Count - 1) - Debug.WriteLine(Now.ToString & " Bloque " & i.ToString & " " & iRegIni & "-" & iRegFin) - p = New IO.MemoryStream(Plantilla) - Utilidades.Docx.Combinar(p, tabla, fs, iRegIni, iRegFin, DevExpress.XtraRichEdit.DocumentFormat.OpenXml, manejadorCalculateVariable) - fs.Close() - GC.Collect() - GC.WaitForPendingFinalizers() - Debug.WriteLine(Now.ToString & " Bloque " & i.ToString & " " & iRegIni & "-" & iRegFin & " a pdf") - Utilidades.Docx.ExportarApdf(sd(i), sp(i)) - Debug.WriteLine(Now.ToString & " Fin Bloque " & i.ToString & " " & iRegIni & "-" & iRegFin & " a pdf") - GC.Collect() - GC.WaitForPendingFinalizers() - ' fs.Close() - Next - Dim msPdfUnidos As New IO.MemoryStream - TSpdfUtils.pdf.UnePdfs(sp, msPdfUnidos) - msPdfUnidos.Seek(0, 0) - Return msPdfUnidos.ToArray - Else - Dim sdocx As String - Do - sdocx = tsl5.Utilidades.ObtieneFicheroAleatorio("docx") - Loop Until Not IO.File.Exists(sdocx) - - Dim fs As New IO.FileStream(sdocx, IO.FileMode.CreateNew, IO.FileAccess.Write) - - Utilidades.Docx.Combinar(New IO.MemoryStream(Plantilla), tabla, fs, 0, tabla.Rows.Count, DevExpress.XtraRichEdit.DocumentFormat.OpenXml, manejadorCalculateVariable) + Dim iNumBloques As Integer = (Int((tabla.Rows.Count - 1) / NumRegBloque)) - 1 + If tabla.Rows.Count Mod NumRegBloque > 1 Then iNumBloques += 1 + Dim sp(iNumBloques) As String + Dim sd(iNumBloques) As String + Dim p As New IO.MemoryStream(Plantilla) + Dim iRegIni As Integer + Dim iRegFin As Integer + For i = 0 To iNumBloques + sd(i) = tsl5.Utilidades.ObtieneFicheroAleatorio("docx") + sp(i) = tsl5.Utilidades.ObtieneFicheroAleatorio("pdf") + Dim fs As New IO.FileStream(sd(i), IO.FileMode.CreateNew, IO.FileAccess.Write) + iRegIni = i * NumRegBloque + iRegFin = Math.Min((i * NumRegBloque) + NumRegBloque - 1, tabla.Rows.Count - 1) + Debug.WriteLine(Now.ToString & " Bloque " & i.ToString & " " & iRegIni & "-" & iRegFin) + p = New IO.MemoryStream(Plantilla) + Utilidades.Docx.Combinar(p, tabla, fs, iRegIni, iRegFin, DevExpress.XtraRichEdit.DocumentFormat.OpenXml, manejadorCalculateVariable) fs.Close() - Return IO.File.ReadAllBytes(sdocx) ' tsl5.Ficheros.FicheroAArrayBytes(sdocx) - End If + GC.Collect() + GC.WaitForPendingFinalizers() + Debug.WriteLine(Now.ToString & " Bloque " & i.ToString & " " & iRegIni & "-" & iRegFin & " a pdf") + Utilidades.Docx.ExportarApdf(sd(i), sp(i)) + Debug.WriteLine(Now.ToString & " Fin Bloque " & i.ToString & " " & iRegIni & "-" & iRegFin & " a pdf") + GC.Collect() + GC.WaitForPendingFinalizers() + ' fs.Close() + Next + Dim msPdfUnidos As New IO.MemoryStream + TSpdfUtils.pdf.UnePdfs(sp, msPdfUnidos) + msPdfUnidos.Seek(0, 0) + Return msPdfUnidos.ToArray Catch ex As Exception Throw New Exception(ex.Message, ex) End Try