02/06/2026 V 5.0.9 Se cambia sobrecarga de CombinaDocx a una nueva funcion CombinaDocxPdfPorBloques
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user