02/06/2026 V 5.0.8 Se añade parametro opcional a docx.combinar
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<package >
|
<package >
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>tsWPF</id>
|
<id>tsWPF</id>
|
||||||
<version>5.0.7.0</version>
|
<version>5.0.8.0</version>
|
||||||
<authors>Tecnosis</authors>
|
<authors>Tecnosis</authors>
|
||||||
<owners>Tecnosis</owners>
|
<owners>Tecnosis</owners>
|
||||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||||
|
|||||||
@@ -55,10 +55,14 @@ Imports System.Windows
|
|||||||
' mediante el asterisco ('*'), como se muestra a continuación:
|
' mediante el asterisco ('*'), como se muestra a continuación:
|
||||||
' <Assembly: AssemblyVersion("1.0.*")>
|
' <Assembly: AssemblyVersion("1.0.*")>
|
||||||
|
|
||||||
<Assembly: AssemblyVersion("5.0.7.0")>
|
<Assembly: AssemblyVersion("5.0.8.0")>
|
||||||
<Assembly: AssemblyFileVersion("5.0.7.0")>
|
<Assembly: AssemblyFileVersion("5.0.8.0")>
|
||||||
|
|
||||||
|
|
||||||
|
' Cambios en la versión 5.0.8.0
|
||||||
|
|
||||||
|
' 02/06/2026 V 5.0.8 Se añade parametro opcional a docx.combinar
|
||||||
|
|
||||||
' Cambios en la versión 5.0.7.0
|
' Cambios en la versión 5.0.7.0
|
||||||
|
|
||||||
' 28/05/2026 V 5.0.7 Actualización de dependencias
|
' 28/05/2026 V 5.0.7 Actualización de dependencias
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ Imports System.Data
|
|||||||
|
|
||||||
Namespace Utilidades
|
Namespace Utilidades
|
||||||
Public Class Docx
|
Public Class Docx
|
||||||
Public Shared Function CombinaDocx(tabla As DataTable, Plantilla() As Byte, FormatoPDF As Boolean) As IO.MemoryStream
|
Public Shared Function CombinaDocx(tabla As DataTable, Plantilla() As Byte, FormatoPDF As Boolean, Optional manejadorCalculateVariable As CalculateDocumentVariableEventHandler = Nothing) As IO.MemoryStream
|
||||||
Try
|
Try
|
||||||
Dim ms As New IO.MemoryStream
|
Dim ms As New IO.MemoryStream
|
||||||
'Dim fs As New IO.FileStream("c:\tmp\pruebamerge.docx", IO.FileMode.Create)
|
'Dim fs As New IO.FileStream("c:\tmp\pruebamerge.docx", IO.FileMode.Create)
|
||||||
Utilidades.Docx.Combinar(New IO.MemoryStream(Plantilla), tabla, ms, 0, tabla.Rows.Count, DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
|
Utilidades.Docx.Combinar(New IO.MemoryStream(Plantilla), tabla, ms, 0, tabla.Rows.Count, DevExpress.XtraRichEdit.DocumentFormat.OpenXml, manejadorCalculateVariable)
|
||||||
ms.Seek(0, IO.SeekOrigin.Begin)
|
ms.Seek(0, IO.SeekOrigin.Begin)
|
||||||
'Dim fs As New IO.FileStream("c:\tmp\ms.docx", IO.FileMode.Create)
|
'Dim fs As New IO.FileStream("c:\tmp\ms.docx", IO.FileMode.Create)
|
||||||
'ms.WriteTo(fs)
|
'ms.WriteTo(fs)
|
||||||
@@ -29,7 +29,7 @@ Namespace Utilidades
|
|||||||
Throw New Exception(ex.Message, ex)
|
Throw New Exception(ex.Message, ex)
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
Public Shared Function CombinaDocx(tabla As DataTable, Plantilla() As Byte, FormatoPDF As Boolean, Optional NumRegBloque As Integer = 1000) As Byte()
|
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()
|
||||||
Try
|
Try
|
||||||
|
|
||||||
If FormatoPDF Then
|
If FormatoPDF Then
|
||||||
@@ -49,7 +49,7 @@ Namespace Utilidades
|
|||||||
iRegFin = Math.Min((i * NumRegBloque) + NumRegBloque - 1, tabla.Rows.Count - 1)
|
iRegFin = Math.Min((i * NumRegBloque) + NumRegBloque - 1, tabla.Rows.Count - 1)
|
||||||
Debug.WriteLine(Now.ToString & " Bloque " & i.ToString & " " & iRegIni & "-" & iRegFin)
|
Debug.WriteLine(Now.ToString & " Bloque " & i.ToString & " " & iRegIni & "-" & iRegFin)
|
||||||
p = New IO.MemoryStream(Plantilla)
|
p = New IO.MemoryStream(Plantilla)
|
||||||
Utilidades.Docx.Combinar(p, tabla, fs, iRegIni, iRegFin, DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
|
Utilidades.Docx.Combinar(p, tabla, fs, iRegIni, iRegFin, DevExpress.XtraRichEdit.DocumentFormat.OpenXml, manejadorCalculateVariable)
|
||||||
fs.Close()
|
fs.Close()
|
||||||
GC.Collect()
|
GC.Collect()
|
||||||
GC.WaitForPendingFinalizers()
|
GC.WaitForPendingFinalizers()
|
||||||
@@ -72,7 +72,7 @@ Namespace Utilidades
|
|||||||
|
|
||||||
Dim fs As New IO.FileStream(sdocx, IO.FileMode.CreateNew, IO.FileAccess.Write)
|
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)
|
Utilidades.Docx.Combinar(New IO.MemoryStream(Plantilla), tabla, fs, 0, tabla.Rows.Count, DevExpress.XtraRichEdit.DocumentFormat.OpenXml, manejadorCalculateVariable)
|
||||||
fs.Close()
|
fs.Close()
|
||||||
Return IO.File.ReadAllBytes(sdocx) ' tsl5.Ficheros.FicheroAArrayBytes(sdocx)
|
Return IO.File.ReadAllBytes(sdocx) ' tsl5.Ficheros.FicheroAArrayBytes(sdocx)
|
||||||
End If
|
End If
|
||||||
@@ -81,26 +81,76 @@ Namespace Utilidades
|
|||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Shared Sub Combinar(Plantilla As IO.Stream, Datos As Object, Destino As IO.Stream, PrimerRegistro As Integer, UltimoRegistro As Integer, Formato As DevExpress.XtraRichEdit.DocumentFormat)
|
'Public Shared Sub Combinar(Plantilla As IO.Stream, Datos As Object, Destino As IO.Stream, PrimerRegistro As Integer, UltimoRegistro As Integer, Formato As DevExpress.XtraRichEdit.DocumentFormat)
|
||||||
|
' Try
|
||||||
|
' Dim docServer As New RichEditDocumentServer
|
||||||
|
' docServer.LoadDocument(Plantilla, Formato)
|
||||||
|
' Dim options = docServer.CreateMailMergeOptions()
|
||||||
|
' options.FirstRecordIndex = PrimerRegistro
|
||||||
|
' options.LastRecordIndex = UltimoRegistro
|
||||||
|
' options.MergeMode = API.Native.MergeMode.NewSection
|
||||||
|
' docServer.Options.MailMerge.DataSource = Datos
|
||||||
|
' docServer.Options.MailMerge.ViewMergedData = True
|
||||||
|
' docServer.Options.Export.Html.EmbedImages = True
|
||||||
|
' docServer.Options.MailMerge.ActiveRecord = 0
|
||||||
|
' docServer.MailMerge(options, Destino, Formato)
|
||||||
|
' docServer.Dispose()
|
||||||
|
' GC.Collect()
|
||||||
|
' GC.WaitForPendingFinalizers()
|
||||||
|
' Catch ex As Exception
|
||||||
|
' Throw New Exception(ex.Message, ex)
|
||||||
|
' End Try
|
||||||
|
'End Sub
|
||||||
|
Public Shared Sub Combinar(
|
||||||
|
Plantilla As IO.Stream,
|
||||||
|
Datos As Object,
|
||||||
|
Destino As IO.Stream,
|
||||||
|
PrimerRegistro As Integer,
|
||||||
|
UltimoRegistro As Integer,
|
||||||
|
Formato As DevExpress.XtraRichEdit.DocumentFormat,
|
||||||
|
Optional manejadorCalculateVariable As CalculateDocumentVariableEventHandler = Nothing
|
||||||
|
)
|
||||||
|
|
||||||
Try
|
Try
|
||||||
Dim docServer As New RichEditDocumentServer
|
Dim docServer As New RichEditDocumentServer()
|
||||||
|
|
||||||
|
' Cargar plantilla
|
||||||
docServer.LoadDocument(Plantilla, Formato)
|
docServer.LoadDocument(Plantilla, Formato)
|
||||||
|
|
||||||
|
' Si el usuario pasa un manejador, lo enganchamos
|
||||||
|
If manejadorCalculateVariable IsNot Nothing Then
|
||||||
|
AddHandler docServer.CalculateDocumentVariable, manejadorCalculateVariable
|
||||||
|
End If
|
||||||
|
|
||||||
|
' Configuración del MailMerge
|
||||||
Dim options = docServer.CreateMailMergeOptions()
|
Dim options = docServer.CreateMailMergeOptions()
|
||||||
options.FirstRecordIndex = PrimerRegistro
|
options.FirstRecordIndex = PrimerRegistro
|
||||||
options.LastRecordIndex = UltimoRegistro
|
options.LastRecordIndex = UltimoRegistro
|
||||||
options.MergeMode = API.Native.MergeMode.NewSection
|
options.MergeMode = API.Native.MergeMode.NewSection
|
||||||
|
|
||||||
docServer.Options.MailMerge.DataSource = Datos
|
docServer.Options.MailMerge.DataSource = Datos
|
||||||
docServer.Options.MailMerge.ViewMergedData = True
|
docServer.Options.MailMerge.ViewMergedData = True
|
||||||
docServer.Options.Export.Html.EmbedImages = True
|
docServer.Options.Export.Html.EmbedImages = True
|
||||||
docServer.Options.MailMerge.ActiveRecord = 0
|
docServer.Options.MailMerge.ActiveRecord = 0
|
||||||
|
|
||||||
|
' Ejecutar combinación
|
||||||
docServer.MailMerge(options, Destino, Formato)
|
docServer.MailMerge(options, Destino, Formato)
|
||||||
|
|
||||||
|
' Desenganchar el manejador si se usó
|
||||||
|
If manejadorCalculateVariable IsNot Nothing Then
|
||||||
|
RemoveHandler docServer.CalculateDocumentVariable, manejadorCalculateVariable
|
||||||
|
End If
|
||||||
|
|
||||||
docServer.Dispose()
|
docServer.Dispose()
|
||||||
GC.Collect()
|
GC.Collect()
|
||||||
GC.WaitForPendingFinalizers()
|
GC.WaitForPendingFinalizers()
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Throw New Exception(ex.Message, ex)
|
Throw New Exception(ex.Message, ex)
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Public Shared Sub ExportarApdf(FicheroOrigen As String, FicheroDestino As String)
|
Public Shared Sub ExportarApdf(FicheroOrigen As String, FicheroDestino As String)
|
||||||
Try
|
Try
|
||||||
Dim docServer As New RichEditDocumentServer
|
Dim docServer As New RichEditDocumentServer
|
||||||
@@ -298,11 +348,11 @@ Namespace Utilidades
|
|||||||
sourceSection.EndUpdateFooter(source)
|
sourceSection.EndUpdateFooter(source)
|
||||||
targetSection.EndUpdateFooter(target)
|
targetSection.EndUpdateFooter(target)
|
||||||
End Sub
|
End Sub
|
||||||
Public Shared Function CombinaDocxStream(Datos As Object, Plantilla() As Byte, PrimerRegistro As Integer, UltimoRegistro As Integer, FormatoPDF As Boolean) As IO.Stream
|
Public Shared Function CombinaDocxStream(Datos As Object, Plantilla() As Byte, PrimerRegistro As Integer, UltimoRegistro As Integer, FormatoPDF As Boolean, Optional manejadorCalculateVariable As CalculateDocumentVariableEventHandler = Nothing) As IO.Stream
|
||||||
Try
|
Try
|
||||||
Dim ms As New IO.MemoryStream
|
Dim ms As New IO.MemoryStream
|
||||||
'Dim fs As New IO.FileStream("c:\tmp\pruebamerge.docx", IO.FileMode.Create)
|
'Dim fs As New IO.FileStream("c:\tmp\pruebamerge.docx", IO.FileMode.Create)
|
||||||
Utilidades.Docx.Combinar(New IO.MemoryStream(Plantilla), Datos, ms, PrimerRegistro, UltimoRegistro, Global.DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
|
Utilidades.Docx.Combinar(New IO.MemoryStream(Plantilla), Datos, ms, PrimerRegistro, UltimoRegistro, Global.DevExpress.XtraRichEdit.DocumentFormat.OpenXml, manejadorCalculateVariable)
|
||||||
If ms.CanSeek Then ms.Seek(0, IO.SeekOrigin.Begin)
|
If ms.CanSeek Then ms.Seek(0, IO.SeekOrigin.Begin)
|
||||||
'Dim fs As New IO.FileStream("c:\tmp\ms.docx", IO.FileMode.Create)
|
'Dim fs As New IO.FileStream("c:\tmp\ms.docx", IO.FileMode.Create)
|
||||||
'ms.WriteTo(fs)
|
'ms.WriteTo(fs)
|
||||||
|
|||||||
Reference in New Issue
Block a user