Noticias Weblogs Foros Wiki Código

RecorteX

» vbnet
458 usuarios y 235 recortes de código
Usuario

Contraseña
Crear cuenta
Estás viendo los recortes de la etiqueta vbnet

RSS
Recortes: 27

Etiquetas relacionadas:
xml
vb
csharp
2005
url
items
signo
double
validacion
negativos
sql
dropdown
net
asp
string
forma
ventana
numero
titulo
formato
version
pesos
dataset

Traer valores atributos de un xml, cuando usa namespaces

Traer valores atributos de un xml, cuando usa namespaces
 
   Private Function GenerarXML(ByVal xmlStr As String, ByVal appendBuffer As String, ByRef strFileName As String) As String
        Dim xmlStrOriginal As String = xmlStr
        Dim xmlDoc As New XmlDocument
        Dim xnav As XPath.XPathNavigator
        Dim mngr As New XmlNamespaceManager(New NameTable)
        mngr.AddNamespace("ns", "http://www.dominio.com/Schemas/Documentos")
        Dim enc As XmlElement
 
        xmlDoc.LoadXml(xmlStr)
        enc = xmlDoc.SelectSingleNode("Nodo1/Nodo2/ns:nsNodo1/ns:nsNodo2", mngr)
        xmlDoc.LoadXml(enc.OuterXml)
        xnav = xmlDoc.CreateNavigator()
        Att1 = xnav.Evaluate("string(/*/@Att1)")
        Att2 = xnav.Evaluate("string(/*/@Att2)")
 
        Return xmlStr
    End Function
 

Copiar y Pegar objetos al clipboard

Copiar y Pegar objetos en vb.net

Para subir al Clipboard
 
  Dim data As New Object
  Dim data_object As New DataObject
  data_object.SetData("Descripcion o identificador del objeto", data)
  Clipboard.SetDataObject(data_object)
 
Para bajar del Clipboard
 
  Dim iDataObject As IDataObject = Clipboard.GetDataObject()
  If iDataObject.GetDataPresent("Descripcion o identificador del objeto") Then
    Dim data As New Object
    data = DirectCast(iDataObject.GetData("Descripcion o identificador del objeto"), object)
  End If
 

Eliminar acentos en vb.net framework 2.x

 
Imports System
Imports System.Text
Imports System.Text.RegularExpressions.Regex
 
Dim reg As RegularExpressions.Regex
Dim textoOriginal As String = "Mañana será otro día"
'transformación UNICODE
Dim textoNormalizado As String = textoOriginal.Normalize(NormalizationForm.FormD)
 
'coincide todo lo que no sean letras y números ascii o espacio
'y lo reemplazamos por una cadena vacía.
 
reg = New RegularExpressions.Regex("[^a-zA-Z0-9 ]")
Dim textoSinAcentos As String = reg.Replace(textoNormalizado, "")
         
Debug.WriteLine(textoSinAcentos)
'muestra 'Manana sera otro dia'
 

Funcion para eliminar acentos con FrameWork 1.*:

 
Dim ConSignos As String ="áàäéèëíìïóòöúùü�ÀÄÉÈË�?Ì�?ÓÒÖÚÙÜçÇ"
Dim SinSignos As String ="aaaeeeiiiooouuuAAAEEEIIIOOOUUUçÇ"
Dim v as integer
Dim texto as string
 
for(v=0;v<SinSignos.Length;v++) {
 
 Dim i As string=ConSignos.Substring(v,1)
 Dim j As string=SinSignos.Substring(v,1)
 
 texto=texto.replace(i,j)
}
 

Transormacion Xsl en VB.net

Este proceso usa un xml y un xsl de entrada y regresa el xml transformado
 
  -----------------------------------------------------------------------------
    <summary>
    Transforma un xml en otro xml
    </summary>
    <param name="txt">un string que contiene el xml origen</param>
    <param name="xslFile">Archivo xsl para la transformacion</param>
    <returns>el xml transformado</returns>
    -----------------------------------------------------------------------------
   Private Function xslTrans(ByVal txt As String, ByVal xslFile As String) As XmlDocument
       Dim xslTran As New XslTransform
       Dim oDocOut As New XmlDocument
       Dim oDoc As New XmlDocument
       Dim oNav As XPath.XPathNavigator
       Dim oXsl As XmlTextReader
       Try
           oXsl = New XmlTextReader(xslFile)
           oDoc.LoadXml(txt)
           oNav = oDoc.CreateNavigator()
           xslTran.Load(oXsl, Nothing, Me.GetType().Assembly.Evidence)
           oDocOut.Load(xslTran.Transform(oNav, Nothing, New Xml.XmlUrlResolver))
       Catch ex As Exception
           Console.Write("Error:" + vbCr + ex.Message)
       End Try
       oDocOut.Normalize()
       Return oDocOut
   End Function
 

Convertir un texto delimitado por comas a matriz

 
      Function LeeDatos(ByVal txt As String) As Array
        Dim rpr As Integer = 30
        Dim comas As Integer = 0
        Dim reng As Integer = 0
        Dim arr(rpr, 0) As String
        Dim car As Char
        For Each car In txt
            If car <> Chr(10) Then
                If (car = Chr(13)) Then car = ","
                If (car <> ",") Then
                    arr(comas, reng) = arr(comas, reng) + car
                Else
                    If comas = rpr Then
                        comas = 0
                        reng = reng + 1
                        ReDim Preserve arr(rpr, reng)
                    Else
                        comas = comas + 1
                    End If
                End If
            End If
        Next
        ReDim Preserve arr(rpr, reng - 1)
        Return arr
    End Function
 

Exportar a Excel

Exportar a Excel

 
  		public static void DT2xls(System.Web.HttpResponse Response,  DataTable dt)
		{
			// exportar a xls
			Response.Clear();
			Response.Buffer= true;
			Response.AddHeader("Content-Disposition", "attachment; filename=Export.xls");
			Response.ContentType = "application/vnd.ms-excel";
			System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
			System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
			System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid();
			dg.DataSource = dt;
			dg.DataBind();
			dg.RenderControl(oHtmlTextWriter);
			Response.Write(oStringWriter);
			Response.End();
		}
 

Para consola

 
    Public Sub htmlExport()
        Dim gvEx As New System.Web.UI.WebControls.GridView
        gvEx.AutoGenerateColumns = True
        gvEx.AllowSorting = False
        gvEx.AllowPaging = False
        Dim stringWrite As New System.IO.StringWriter
        Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
        gvEx.DataSource = Me.DataSource
        gvEx.DataBind()
        gvEx.RenderControl(htmlWrite)
        WriteFile(Me.FileName, stringWrite.ToString())
    End Sub
 

Usando excel

 
    Public Sub ExcelExport()
        Dim oexcel As Excel.Application
        Try
            If File.Exists(FileName) Then File.Delete(FileName)
            'create new excel application
            oexcel = CreateObject("Excel.Application")
            oexcel.Application.DisplayAlerts = True
            'add a new workbook
            'obook = oexcel.Workbooks.Open(FileName)
            Dim obook As Excel.Workbook = oexcel.Workbooks.Add()
            Dim ws As Excel.Worksheet = obook.Sheets(1)
 
            ' Add each row of data to the sheet.
            ' The sheet cell row is incremented by one because the first row was used for the header.
            For rowIndex As Integer = 1 To DataSource.Rows.Count
                For colIndex As Integer = 1 To DataSource.Columns.Count
                    TryCast(ws.Cells(rowIndex + 1, colIndex), Excel.Range).Value2 = DataSource.Rows(rowIndex - 1)(colIndex - 1).ToString()
                Next
            Next
 
            ' Create the headers on the sheet.
            For colIndex As Integer = 1 To DataSource.Columns.Count
                TryCast(ws.Cells(1, colIndex), Excel.Range).Value2 = DataSource.Columns(colIndex - 1).ColumnName
                TryCast(ws.Cells(1, colIndex), Excel.Range).Font.Bold = True
                TryCast(ws.Cells(1, colIndex), Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
                TryCast(ws.Cells(1, colIndex), Excel.Range).EntireColumn.AutoFit()
            Next
 
 
            oexcel.Visible = False
 
            If Password <> "" Then
                obook.SaveAs(FileName, Excel.XlFileFormat.xlWorkbookNormal, Password, Nothing, False, False, Excel.XlSaveAsAccessMode.xlExclusive, False, False, Nothing, Nothing)
            Else
                obook.SaveAs(FileName)
            End If
            'end application object and session
            obook.Close()
            obook = Nothing
            oexcel.Quit()
            oexcel = Nothing
        Catch ex As Exception
            Throw New System.Exception(ex.Message)
        Finally
        End Try
    End Sub
 
info@recortex.com - Proyecto: Juanjo Navarro, 2006 - Diseño: Albin - Información legal y técnica