ModExtensiones: Validar que el nombre de la hoja sea válido, si no, sustituir caracteres y/o truncar
This commit is contained in:
@@ -145,6 +145,23 @@ Namespace Extensiones
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Function Truncate(value As String, length As Integer) As String
|
||||
' If argument is too big, return the original string.
|
||||
' ... Otherwise take a substring from the string's start index.
|
||||
If length > value.Length Then
|
||||
Return value
|
||||
Else
|
||||
Return value.Substring(0, length)
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Function ValidFileName(ByVal name As String) As String
|
||||
For Each c As Char In System.IO.Path.GetInvalidFileNameChars()
|
||||
name = name.Replace(c.ToString(), "_")
|
||||
Next
|
||||
Return Truncate(name, 31)
|
||||
End Function
|
||||
|
||||
Public Class RespuestaCancelacionSAT
|
||||
Public Property Verificado As Boolean = False
|
||||
Public Property CveEstatus As Integer = 0
|
||||
@@ -2527,7 +2544,7 @@ Namespace Extensiones
|
||||
Dim TotalRowFooter As Integer = 2
|
||||
|
||||
Dim worksheet = excel.Worksheets(0)
|
||||
worksheet.Name = NombreArchivoXLSx
|
||||
worksheet.Name = ValidFileName(NombreArchivoXLSx)
|
||||
worksheet.Rows.InsertEmpty(0, TotalRowHeader)
|
||||
Dim celdasConTexto = worksheet.GetUsedCellRange(True)
|
||||
celdasConTexto.Style.Font.Name = "Calibri Light"
|
||||
@@ -2603,10 +2620,10 @@ Namespace Extensiones
|
||||
<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)
|
||||
GemBox.Spreadsheet.SpreadsheetInfo.SetLicense(SerialGemBoxSpreadsheet)
|
||||
If Dt.TableName Is Nothing Then Dt.TableName = NombreArchivoXLSx
|
||||
If Dt.TableName Is Nothing Then Dt.TableName = ValidFileName(NombreArchivoXLSx)
|
||||
|
||||
Dim excel As New GemBox.Spreadsheet.ExcelFile
|
||||
Dim item = excel.Worksheets.Add(Dt.TableName)
|
||||
Dim item = excel.Worksheets.Add(Truncate(Dt.TableName, 31))
|
||||
|
||||
item.InsertDataTable(Dt, New InsertDataTableOptions() With
|
||||
{
|
||||
@@ -2620,6 +2637,7 @@ Namespace Extensiones
|
||||
Dim TotalRowFooter As Integer = 2
|
||||
|
||||
Dim worksheet = excel.Worksheets(0)
|
||||
'worksheet.Name = ValidFileName(NombreArchivoXLSx)
|
||||
worksheet.Rows.InsertEmpty(0, TotalRowHeader)
|
||||
Dim celdasConTexto = worksheet.GetUsedCellRange(True)
|
||||
celdasConTexto.Style.Font.Name = "Calibri Light"
|
||||
|
||||
Reference in New Issue
Block a user