ModExtensiones: Hacer ValidFileName de propósito general
Por si se llega a ocupar en otra cosa, que no solo sea para las hojas de excel
This commit is contained in:
@@ -155,11 +155,14 @@ Namespace Extensiones
|
|||||||
End If
|
End If
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Function ValidFileName(ByVal name As String) As String
|
Public Function ValidFileName(name As String, Optional maxChars As Integer = -1) As String
|
||||||
For Each c As Char In System.IO.Path.GetInvalidFileNameChars()
|
For Each c As Char In System.IO.Path.GetInvalidFileNameChars()
|
||||||
name = name.Replace(c.ToString(), "_")
|
name = name.Replace(c.ToString(), "_")
|
||||||
Next
|
Next
|
||||||
Return Truncate(name, 31)
|
If maxChars > 0 AndAlso maxChars < 256 Then
|
||||||
|
Return Truncate(name, maxChars)
|
||||||
|
End If
|
||||||
|
Return Truncate(name, 255)
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Class RespuestaCancelacionSAT
|
Public Class RespuestaCancelacionSAT
|
||||||
@@ -2544,7 +2547,7 @@ Namespace Extensiones
|
|||||||
Dim TotalRowFooter As Integer = 2
|
Dim TotalRowFooter As Integer = 2
|
||||||
|
|
||||||
Dim worksheet = excel.Worksheets(0)
|
Dim worksheet = excel.Worksheets(0)
|
||||||
worksheet.Name = ValidFileName(NombreArchivoXLSx)
|
worksheet.Name = ValidFileName(NombreArchivoXLSx, 31)
|
||||||
worksheet.Rows.InsertEmpty(0, TotalRowHeader)
|
worksheet.Rows.InsertEmpty(0, TotalRowHeader)
|
||||||
Dim celdasConTexto = worksheet.GetUsedCellRange(True)
|
Dim celdasConTexto = worksheet.GetUsedCellRange(True)
|
||||||
celdasConTexto.Style.Font.Name = "Calibri Light"
|
celdasConTexto.Style.Font.Name = "Calibri Light"
|
||||||
@@ -2620,10 +2623,10 @@ Namespace Extensiones
|
|||||||
<Runtime.CompilerServices.Extension()>
|
<Runtime.CompilerServices.Extension()>
|
||||||
Public Sub ExportToExcelG(Dt As DataTable, NombreArchivoXLSx As String, Optional Titulo As String = "Reporte", Optional Usuario As Usuario = Nothing, Optional Filtros As String = "", Optional AlturaImagen As Double = 100, Optional AnchoImagen As Double = 100)
|
Public Sub ExportToExcelG(Dt As DataTable, NombreArchivoXLSx As String, Optional Titulo As String = "Reporte", Optional Usuario As Usuario = Nothing, Optional Filtros As String = "", Optional AlturaImagen As Double = 100, Optional AnchoImagen As Double = 100)
|
||||||
GemBox.Spreadsheet.SpreadsheetInfo.SetLicense(SerialGemBoxSpreadsheet)
|
GemBox.Spreadsheet.SpreadsheetInfo.SetLicense(SerialGemBoxSpreadsheet)
|
||||||
If Dt.TableName Is Nothing Then Dt.TableName = ValidFileName(NombreArchivoXLSx)
|
If Dt.TableName Is Nothing Then Dt.TableName = NombreArchivoXLSx
|
||||||
|
|
||||||
Dim excel As New GemBox.Spreadsheet.ExcelFile
|
Dim excel As New GemBox.Spreadsheet.ExcelFile
|
||||||
Dim item = excel.Worksheets.Add(ValidFileName(Dt.TableName))
|
Dim item = excel.Worksheets.Add(ValidFileName(Dt.TableName, 31))
|
||||||
|
|
||||||
item.InsertDataTable(Dt, New InsertDataTableOptions() With
|
item.InsertDataTable(Dt, New InsertDataTableOptions() With
|
||||||
{
|
{
|
||||||
@@ -2637,7 +2640,7 @@ Namespace Extensiones
|
|||||||
Dim TotalRowFooter As Integer = 2
|
Dim TotalRowFooter As Integer = 2
|
||||||
|
|
||||||
Dim worksheet = excel.Worksheets(0)
|
Dim worksheet = excel.Worksheets(0)
|
||||||
'worksheet.Name = ValidFileName(NombreArchivoXLSx)
|
'worksheet.Name = ValidFileName(NombreArchivoXLSx, 31)
|
||||||
worksheet.Rows.InsertEmpty(0, TotalRowHeader)
|
worksheet.Rows.InsertEmpty(0, TotalRowHeader)
|
||||||
Dim celdasConTexto = worksheet.GetUsedCellRange(True)
|
Dim celdasConTexto = worksheet.GetUsedCellRange(True)
|
||||||
celdasConTexto.Style.Font.Name = "Calibri Light"
|
celdasConTexto.Style.Font.Name = "Calibri Light"
|
||||||
|
|||||||
Reference in New Issue
Block a user