elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.


Tema destacado: Introducción a Git (Primera Parte)


  Mostrar Mensajes
Páginas: 1 ... 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 [698] 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 ... 1254
6971  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 22 Agosto 2014, 20:08 pm
Por algún motivo no me puedo instalar el MS Office así que tuve que buscar alguna alternativa para poder seguir desarrollando con manejo de Excel sin interop, y di con esta magnifica librería, NPOI:



http://npoi.codeplex.com/

Tomé los ejemplos oficiales en C# y escribí los siguientes ejemplos en VB.NET



Crear un workbook:

Código
  1. #Region " Create a WorkBook "
  2.  
  3.        ' Create the excel workbook.
  4.        Dim workbook As IWorkbook = New XSSFWorkbook()
  5.  
  6.        ' Create a sheet.
  7.        Dim sheet As ISheet = workbook.CreateSheet("Sheet A1")
  8.  
  9.        ' Create a cell.
  10.        Dim cell As ICell = sheet.CreateRow(0).CreateCell(0)
  11.  
  12.        ' Set cell value.
  13.        cell.SetCellValue("This is a test")
  14.  
  15.        ' Set the width of column A1.
  16.        sheet.SetColumnWidth(0, 50 * 256)
  17.  
  18.        ' Set the height of row A1.
  19.        sheet.CreateRow(0).Height = 200
  20.  
  21.        ' Save changes.
  22.        Using sw As IO.FileStream = IO.File.Create(".\Create a Workbook Example.xlsx")
  23.            workbook.Write(sw)
  24.        End Using
  25.  
  26. #End Region



Deinifir la cabecera y el pie de página:

Código
  1. #Region " Set Header and Footer "
  2.  
  3.    ' Create the excel workbook.
  4.    Dim workbook As IWorkbook = New XSSFWorkbook()
  5.    Dim sheet As ISheet = workbook.CreateSheet("Sheet1") ' Create a sheet.
  6.  
  7.    With sheet
  8.  
  9.    ' Create a cell and add a value.
  10.        .CreateRow(0).CreateCell(1).SetCellValue("test")
  11.  
  12.    ' Set header text.
  13.        .Header.Left = HSSFHeader.Page
  14.  
  15.    ' Page is a static property of HSSFHeader and HSSFFooter.
  16.        .Header.Center = "This is a test sheet"
  17.  
  18.    ' Set footer text.
  19.        .Footer.Left = "Copyright NPOI Team"
  20.        .Footer.Right = "created by Tony Qu(瞿杰)"
  21.  
  22.    End With
  23.  
  24.     Save changes.
  25.    Using sw As IO.FileStream = IO.File.Create(".\Header-Footer Example.xlsx")
  26.        workbook.Write(sw)
  27.    End Using
  28.  
  29. #End Region



Añadir comentarios a una celda:

Código
  1. #Region " Add Comments "
  2.  
  3.    ' Create the excel workbook.
  4.    Dim workbook As IWorkbook = New XSSFWorkbook()
  5.    Dim sheet As ISheet = workbook.CreateSheet("some comments") ' Create the first sheet.
  6.  
  7.    ' Create the drawing patriarch. This is the top level container for all shapes including cell comments.
  8.    Dim patr As IDrawing = sheet.CreateDrawingPatriarch()
  9.  
  10.    ' Create a cell in row 3.
  11.    Dim cell1 As ICell = sheet.CreateRow(3).CreateCell(1)
  12.    cell1.SetCellValue(New XSSFRichTextString("Hello, World"))
  13.  
  14.    ' Create a richtext to use it in the comment.
  15.    Dim strComment As New XSSFRichTextString("This is saying you hello")
  16.  
  17.    ' Create the richtext font style.
  18.    Dim font As IFont = workbook.CreateFont()
  19.    With font
  20.        .FontName = "Arial"
  21.        .FontHeightInPoints = 10
  22.        .Boldweight = CShort(FontBoldWeight.Bold)
  23.        .Color = HSSFColor.Red.Index
  24.    End With
  25.  
  26.    ' Apply font style to the text in the comment.
  27.    strComment.ApplyFont(font)
  28.  
  29.    ' Create a comment, Anchor defines size and position of the comment in worksheet.
  30.    Dim comment1 As IComment = patr.CreateCellComment(New XSSFClientAnchor(0, 0, 0, 0, 4, 2, 6, 5))
  31.    With comment1
  32.  
  33.    ' Set comment text.
  34.        .[String] = strComment
  35.  
  36.    ' Set comment author.
  37.        .Author = "Elektro"
  38.  
  39.    ' By default comments are hidden. This one is always visible.
  40.        .Visible = True
  41.  
  42.    End With
  43.  
  44.    '* The first way to assign comment to a cell is via CellComment method:
  45.    cell1.CellComment = comment1
  46.    '* The second way to assign comment to a cell is to implicitly specify its row and column.
  47.    '* Note: It is possible to set row and column of a non-existing cell.
  48.    comment1.Row = 3
  49.    comment1.Column = 1
  50.  
  51.    ' Save changes.
  52.    Using sw As IO.FileStream = IO.File.Create(".\Comment Example.xlsx")
  53.        workbook.Write(sw)
  54.    End Using
  55.  
  56. #End Region



Definir propiedades personalizadas:

Código
  1. #Region " Set Custom Properties "
  2.  
  3.    ' Create the excel workbook.
  4.    Dim workbook As XSSFWorkbook = New XSSFWorkbook()
  5.    Dim sheet As ISheet = workbook.CreateSheet("Sheet1") ' Create the first sheet.
  6.  
  7.    ' Get the properties.
  8.    Dim props As POIXMLProperties = workbook.GetProperties()
  9.  
  10.    With props ' Set some default properties.
  11.        .CoreProperties.Title = "Properties Example"
  12.        .CoreProperties.Creator = "Elektro"
  13.        .CoreProperties.Created = DateTime.Now
  14.    End With
  15.  
  16.    ' Set a custom property.
  17.    If Not props.CustomProperties.Contains("My Property Name") Then
  18.        props.CustomProperties.AddProperty("My Property Name", "Hello World!")
  19.    End If
  20.  
  21.    ' Save changes.
  22.    Using sw As IO.FileStream = IO.File.Create(".\Properties Example.xlsx")
  23.        workbook.Write(sw)
  24.    End Using
  25.  
  26. #End Region



Rellenar el color de fondo de una celda:

Código
  1. #Region " Fill Cell Background "
  2.  
  3.    ' Create the excel workbook.
  4.    Dim workbook As IWorkbook = New XSSFWorkbook()
  5.  
  6.    ' Create a sheet.
  7.    Dim sheet As ISheet = workbook.CreateSheet("Sheet1")
  8.  
  9.    ' Create a cell.
  10.    Dim cell1 As ICell = sheet.CreateRow(0).CreateCell(0)
  11.  
  12.    ' Set the cell text.
  13.    cell1.SetCellValue("Hello")
  14.  
  15.    ' Set the Background Style.
  16.    Dim style As ICellStyle = workbook.CreateCellStyle()
  17.    With style
  18.        .FillForegroundColor = IndexedColors.Blue.Index
  19.        .FillPattern = FillPattern.BigSpots
  20.        .FillBackgroundColor = IndexedColors.Pink.Index
  21.    End With
  22.  
  23.    ' Fill the cell background.
  24.    cell1.CellStyle = style
  25.  
  26.    ' Save changes.
  27.    Using sw As IO.FileStream = IO.File.Create(".\Fill background Example.xlsx")
  28.        workbook.Write(sw)
  29.    End Using
  30.  
  31. #End Region



Añadir un hyperlink:

Código
  1. #Region " Add HyperLinks "
  2.  
  3.    ' Create the excel workbook.
  4.    Dim workbook As IWorkbook = New XSSFWorkbook()
  5.    Dim cell As ICell = Nothing
  6.    Dim sheet As ISheet = workbook.CreateSheet("Hyperlinks") ' Create the first sheet.
  7.  
  8.    ' Set the Hyperlink style.
  9.    Dim HyperLinkStyle As ICellStyle = workbook.CreateCellStyle()
  10.    Dim HyperLinkFont As IFont = workbook.CreateFont()
  11.    HyperLinkFont.Underline = FontUnderlineType.[Single]
  12.    HyperLinkFont.Color = HSSFColor.Blue.Index
  13.    HyperLinkStyle.SetFont(HyperLinkFont)
  14.  
  15.    ' Link to an URL.
  16.    Dim LinkURL As New XSSFHyperlink(HyperlinkType.Url) With {.Address = "http://poi.apache.org/"}
  17.    cell = sheet.CreateRow(0).CreateCell(0)
  18.    With cell
  19.        .SetCellValue("URL Link")
  20.        .Hyperlink = LinkURL
  21.        .CellStyle = HyperLinkStyle
  22.    End With
  23.  
  24.    ' Link to a file.
  25.    Dim LinkFile As New XSSFHyperlink(HyperlinkType.File) With {.Address = "link1.xls"}
  26.    cell = sheet.CreateRow(1).CreateCell(0)
  27.    With cell
  28.        .SetCellValue("File Link")
  29.        .Hyperlink = LinkFile
  30.        .CellStyle = HyperLinkStyle
  31.    End With
  32.  
  33.    ' Link to an e-amil.
  34.    Dim LinkMail As New XSSFHyperlink(HyperlinkType.Email) With {.Address = "mailto:poi@apache.org?subject=Hyperlinks"}
  35.    With cell
  36.        cell = sheet.CreateRow(2).CreateCell(0)
  37.        .SetCellValue("Email Link")
  38.        .Hyperlink = LinkMail
  39.        .CellStyle = HyperLinkStyle
  40.    End With
  41.  
  42.    ' Link to a place in the workbook.
  43.    Dim LinkSheet As New XSSFHyperlink(HyperlinkType.Document) With {.Address = "'Target ISheet'!A1"}
  44.    Dim sheet2 As ISheet = workbook.CreateSheet("Target ISheet") ' Create a target sheet.
  45.    sheet2.CreateRow(0).CreateCell(0).SetCellValue("Target ICell") ' Create a target cell.
  46.    With cell
  47.        cell = sheet.CreateRow(3).CreateCell(0)
  48.        .SetCellValue("Worksheet Link")
  49.        .Hyperlink = LinkSheet
  50.        .CellStyle = HyperLinkStyle
  51.    End With
  52.  
  53.    ' Save changes.
  54.    Using sw As IO.FileStream = IO.File.Create(".\HyperLink Example.xlsx")
  55.        workbook.Write(sw)
  56.    End Using
  57.  
  58. #End Region



Establecer el estilo de fuente:

Código
  1. #Region " Set Font style "
  2.  
  3.    ' Create the excel workbook.
  4.    Dim workbook As IWorkbook = New XSSFWorkbook()
  5.    Dim sheet1 As ISheet = workbook.CreateSheet("Sheet1") ' Create the first sheet.
  6.  
  7.    ' Create a cell style.
  8.    Dim style1 As ICellStyle = workbook.CreateCellStyle()
  9.  
  10.    ' Create a font style.
  11.    Dim font1 As IFont = workbook.CreateFont()
  12.    With font1 ' underlined, italic, red color, fontsize=20
  13.        .Color = IndexedColors.Red.Index
  14.        .IsItalic = True
  15.        .Underline = FontUnderlineType.[Double]
  16.        .FontHeightInPoints = 20
  17.    End With
  18.  
  19.    ' bind font1 with style1
  20.    style1.SetFont(font1)
  21.  
  22.    ' Create a cell, add text, and apply the font.
  23.    Dim cell1 As ICell = sheet1.CreateRow(1).CreateCell(1)
  24.    With cell1
  25.        .SetCellValue("Hello World!")
  26.        .CellStyle = style1
  27.    End With
  28.  
  29.    ' Save changes.
  30.    Using sw As IO.FileStream = IO.File.Create(".\Font-Style Example.xlsx")
  31.        workbook.Write(sw)
  32.    End Using
  33.  
  34. #End Region



Establecer el tipo de fuente para texto con formato (rich text):

Código
  1. #Region " Set Font style RichText "
  2.  
  3.    ' Create the excel workbook.
  4.    Dim workbook As IWorkbook = New XSSFWorkbook()
  5.    Dim sheet1 As ISheet = workbook.CreateSheet("Sheet1") ' Create the first sheet.
  6.  
  7.    ' Create a cell with rich text.
  8.    Dim cell1 As ICell = sheet1.CreateRow(0).CreateCell(0)
  9.  
  10.    ' Create a richtext.
  11.    Dim richtext As New XSSFRichTextString("Microsoft OfficeTM")
  12.  
  13.    ' Create a font style.
  14.    Dim font1 As IFont = workbook.CreateFont()
  15.    With font1
  16.        .FontHeightInPoints = 12
  17.    End With
  18.    richtext.ApplyFont(0, 16, font1) ' apply font to "Microsoft Office".
  19.  
  20.    ' Create a font style.
  21.    Dim font2 As IFont = workbook.CreateFont()
  22.    With font2
  23.        .TypeOffset = FontSuperScript.Super
  24.        .IsItalic = True
  25.        .Color = IndexedColors.Blue.Index
  26.        .FontHeightInPoints = 8
  27.    End With
  28.    richtext.ApplyFont(16, 18, font2) ' apply font to "TM"
  29.  
  30.    ' Add the richtext into the cell.
  31.    cell1.SetCellValue(richtext)
  32.  
  33.    ' Save changes.
  34.    Using sw As IO.FileStream = IO.File.Create(".\Font-Style RichText Example.xlsx")
  35.        workbook.Write(sw)
  36.    End Using
  37.  
  38. #End Region



Añadir una tabla:

Código
  1. #Region " Add a Table "
  2.  
  3.    ' Create the excel workbook.
  4.    Dim workbook As IWorkbook = New XSSFWorkbook()
  5.    Dim sheet1 As XSSFSheet = DirectCast(workbook.CreateSheet("Sheet1"), XSSFSheet) ' Create the first sheet.
  6.  
  7.    ' Create a cell with text.
  8.    sheet1.CreateRow(0).CreateCell(0).SetCellValue("This is a Sample")
  9.  
  10.    ' Create a table.
  11.    Dim x As Integer = 1
  12.    For i As Integer = 1 To 15
  13.    Dim row As IRow = sheet1.CreateRow(i)
  14.        For j As Integer = 0 To 14
  15.            row.CreateCell(j).SetCellValue(System.Math.Max(System.Threading.Interlocked.Increment(x), x - 1))
  16.        Next j
  17.    Next i
  18.    Dim table As XSSFTable = sheet1.CreateTable()
  19.    table.Name = "Tabella1"
  20.    table.DisplayName = "Tabella1"
  21.  
  22.    ' Save changes.
  23.    Using sw As IO.FileStream = IO.File.Create(".\Table Example.xlsx")
  24.        workbook.Write(sw)
  25.    End Using
  26.  
  27. #End Region



Formatear el valor de una celda:

Código
  1. #Region " Format Cell Data "
  2.  
  3.    Private Sub Test() Handles MyBase.Shown
  4.  
  5.        ' Create the excel workbook.
  6.        Dim workbook As IWorkbook = New XSSFWorkbook()
  7.  
  8.        ' Create a sheet.
  9.        Dim sheet As ISheet = workbook.CreateSheet("Sheet1")
  10.  
  11.        ' Create the format instance.
  12.        Dim format As IDataFormat = workbook.CreateDataFormat()
  13.  
  14.        ' Increase the width of Column A.
  15.        sheet.SetColumnWidth(0, 5000)
  16.  
  17.        ' Create a row and put some cells in it. Rows are 0 based.
  18.        Dim cell1 As ICell = sheet.CreateRow(0).CreateCell(0)
  19.        Dim cell2 As ICell = sheet.CreateRow(1).CreateCell(0)
  20.        Dim cell3 As ICell = sheet.CreateRow(2).CreateCell(0)
  21.        Dim cell4 As ICell = sheet.CreateRow(3).CreateCell(0)
  22.        Dim cell5 As ICell = sheet.CreateRow(4).CreateCell(0)
  23.        Dim cell6 As ICell = sheet.CreateRow(5).CreateCell(0)
  24.        Dim cell7 As ICell = sheet.CreateRow(6).CreateCell(0)
  25.  
  26.        ' Format the cell values.
  27.  
  28.        ' [Cell1]
  29.        ' Number format with 2 digits after the decimal point. eg: "1.20"
  30.        SetValueAndFormat(workbook, cell1, 1.2, HSSFDataFormat.GetBuiltinFormat("0.00"))
  31.  
  32.        ' [Cell2]
  33.        ' RMB currency format with comma. eg: "¥20,000"
  34.        SetValueAndFormat(workbook, cell2, 20000, format.GetFormat("¥#,##0"))
  35.  
  36.        ' [Cell3]
  37.        ' Scentific number format. eg: "3.15E+00"
  38.        SetValueAndFormat(workbook, cell3, 3.151234, format.GetFormat("0.00E+00"))
  39.  
  40.        ' [Cell4]
  41.        ' Percent format, 2 digits after the decimal point. eg: "99.33%"
  42.        SetValueAndFormat(workbook, cell4, 0.99333, format.GetFormat("0.00%"))
  43.  
  44.        ' [Cell5]
  45.        ' Phone number format. eg: "021-65881234"
  46.        SetValueAndFormat(workbook, cell5, 2165881234UI, format.GetFormat("000-00000000"))
  47.  
  48.        ' [Cell6]:
  49.        ' Formula value with datetime style.
  50.        cell6.CellFormula = "DateValue(""2005-11-11"")+TIMEVALUE(""11:11:11"")"
  51.        Dim cellStyle6 As ICellStyle = workbook.CreateCellStyle()
  52.        cellStyle6.DataFormat = HSSFDataFormat.GetBuiltinFormat("m/d/yy h:mm")
  53.        cell6.CellStyle = cellStyle6
  54.  
  55.        ' [Cell7]:
  56.        ' Display current time in AM/PM format.
  57.        SetDate(workbook, cell7, DateTime.Now, format.GetFormat("[$-409]h:mm:ss AM/PM;@"))
  58.  
  59.        ' Save changes.
  60.        Using sw As IO.FileStream = IO.File.Create(".\Formula Example.xlsx")
  61.            workbook.Write(sw)
  62.        End Using
  63.  
  64.    End Sub
  65.  
  66.    Private Shared Sub SetValueAndFormat(ByVal workbook As IWorkbook,
  67.                                         ByVal cell As ICell,
  68.                                         ByVal value As Double,
  69.                                         ByVal formatId As Short)
  70.  
  71.        cell.SetCellValue(value)
  72.        Dim cellStyle As ICellStyle = workbook.CreateCellStyle()
  73.        cellStyle.DataFormat = formatId
  74.        cell.CellStyle = cellStyle
  75.  
  76.    End Sub
  77.  
  78.    Private Shared Sub SetDate(ByVal workbook As IWorkbook,
  79.                               ByVal cell As ICell,
  80.                               ByVal value As DateTime,
  81.                               ByVal formatId As Short)
  82.  
  83.        'set value for the cell
  84.        If Not value = Nothing Then
  85.            cell.SetCellValue(value)
  86.        End If
  87.  
  88.        Dim cellStyle As ICellStyle = workbook.CreateCellStyle()
  89.        cellStyle.DataFormat = formatId
  90.        cell.CellStyle = cellStyle
  91.  
  92.    End Sub
  93.  
  94. #End Region



Ocultar una fila o una columna:

Código
  1. #Region " Hide row or column "
  2.  
  3.    ' Create the excel workbook.
  4.    Dim workbook As IWorkbook = New XSSFWorkbook()
  5.  
  6.    ' Create a sheet.
  7.    Dim sheet As ISheet = workbook.CreateSheet("Sheet1")
  8.  
  9.    ' Create some rows.
  10.    Dim r1 As IRow = sheet.CreateRow(0)
  11.    Dim r2 As IRow = sheet.CreateRow(1)
  12.    Dim r3 As IRow = sheet.CreateRow(2)
  13.    Dim r4 As IRow = sheet.CreateRow(3)
  14.    Dim r5 As IRow = sheet.CreateRow(4)
  15.  
  16.    ' Hide IRow 2.
  17.    r2.ZeroHeight = True
  18.  
  19.    ' Hide column C.
  20.    sheet.SetColumnHidden(2, True)
  21.  
  22.    ' Save changes.
  23.    Using sw As IO.FileStream = IO.File.Create(".\Hide Row or Column Example.xlsx")
  24.        workbook.Write(sw)
  25.    End Using
  26.  
  27. #End Region



Añadir una imagen:

Código
  1.        ' Create the excel workbook.
  2.        Dim workbook As IWorkbook = New XSSFWorkbook()
  3.  
  4.        ' Create a sheet.
  5.        Dim sheet As ISheet = workbook.CreateSheet("PictureSheet")
  6.  
  7.        ' Create the drawing patriarch. This is the top level container for all shapes including cell comments.
  8.        Dim patriarch As IDrawing = sheet.CreateDrawingPatriarch()
  9.  
  10.        ' Create the anchor.
  11.        Dim anchor As New XSSFClientAnchor(500, 200, 0, 0, 2, 2, 4, 7)
  12.        anchor.AnchorType = 2
  13.  
  14.        ' Load the picture and get the picture index in the workbook.
  15.        Dim imageId As Integer = LoadImage("C:\Users\Administrador\Desktop\4t0n.png", workbook)
  16.        Dim picture As XSSFPicture = DirectCast(patriarch.CreatePicture(anchor, imageId), XSSFPicture)
  17.  
  18.        ' Reset the image to the original size.
  19.        ' Note: Resize will reset client anchor you set.
  20.        'picture.Resize();  
  21.  
  22.        ' Save changes.
  23.        Using sw As IO.FileStream = IO.File.Create(".\Add Picture Example.xlsx")
  24.            workbook.Write(sw)
  25.        End Using
  26.  
  27.  
  28.    Public Shared Function LoadImage(path As String, wb As IWorkbook) As Integer
  29.        Dim file As New FileStream(path, FileMode.Open, FileAccess.Read)
  30.        Dim buffer As Byte() = New Byte(file.Length - 1) {}
  31.        file.Read(buffer, 0, CInt(file.Length))
  32.        Return wb.AddPicture(buffer, PictureType.JPEG)
  33.    End Function



Unir celdas:

Código
  1.        ' Create the excel workbook.
  2.        Dim workbook As IWorkbook = New XSSFWorkbook()
  3.  
  4.        ' Create a sheet.
  5.        Dim sheet As ISheet = workbook.CreateSheet("Sheet1")
  6.  
  7.        ' Create a cell.
  8.        Dim cell As ICell = sheet.CreateRow(1).CreateCell(1)
  9.        cell.SetCellValue(New XSSFRichTextString("This is a test of merging"))
  10.  
  11.        ' Merge B2 cell with C2 cell.
  12.        sheet.AddMergedRegion(New CellRangeAddress(1, 1, 1, 2))
  13.  
  14.        ' Save changes.
  15.        Using sw As IO.FileStream = IO.File.Create(".\Merge Cells Example.xlsx")
  16.            workbook.Write(sw)
  17.        End Using



Proteger con contraseña:

Código
  1.        ' Create the excel workbook.
  2.        Dim workbook As IWorkbook = New XSSFWorkbook()
  3.  
  4.        ' Create a sheet.
  5.        Dim sheet As XSSFSheet = DirectCast(workbook.CreateSheet("Sheet A1"), XSSFSheet)
  6.  
  7.        With sheet ' Lock accessing excel operations.
  8.            .LockFormatRows()
  9.            .LockFormatCells()
  10.            .LockFormatColumns()
  11.            .LockDeleteColumns()
  12.            .LockDeleteRows()
  13.            .LockInsertHyperlinks()
  14.            .LockInsertColumns()
  15.            .LockInsertRows()
  16.        End With
  17.  
  18.        ' Set the password to unprotect:
  19.        Dim password As String = "Your Password"
  20.        sheet.ProtectSheet(password)
  21.  
  22.        ' Save changes.
  23.        Using sw As IO.FileStream = IO.File.Create(".\Protect Cells Example.xlsx")
  24.            workbook.Write(sw)
  25.        End Using


EDITO:


Como leer un workbook:

Código
  1.        ' The existing workbook filepath.
  2.        Dim WorkBookFile As String = "C:\MyWorkBook.xlsx"
  3.  
  4.        ' Create the excel workbook instance.
  5.        Dim workbook As IWorkbook = Nothing
  6.  
  7.        ' Load the workbook.
  8.        Using file As New IO.FileStream(WorkBookFile, IO.FileMode.Open, IO.FileAccess.Read)
  9.            workbook = New XSSFWorkbook(file)
  10.        End Using
  11.  
  12.        ' Get the first sheet.
  13.        Dim sheet As ISheet = workbook.GetSheetAt(0)
  14.  
  15.        ' Get the first row.
  16.        Dim row As IRow = sheet.GetRow(0)
  17.  
  18.        ' Create a cell.
  19.        Dim cell As ICell = row.CreateCell(1)
  20.  
  21.        ' Get the cell value.
  22.        If String.IsNullOrEmpty(cell.StringCellValue) Then ' If value is emty then...
  23.  
  24.            ' Set cell value.
  25.            cell.SetCellValue("This is a test")
  26.  
  27.        End If
  28.  
  29.        ' Save changes.
  30.        Using sw As IO.FileStream = IO.File.Create(WorkBookFile)
  31.            workbook.Write(sw)
  32.        End Using
6972  Programación / Scripting / Re: Ayuda Mini-vbscript para aumentar/disminuir velocidad del raton DPI en: 22 Agosto 2014, 16:29 pm
lo e intentado es por medio de Sendkeys y con todas las pulsaciones que tendria que hacer,pero sin resultado.

En un lenguaje simple como es VBS la manera que has mencionado es la única que puedes llevar a cabo.

También puedes recurrir a una modificación del registre, el valor [HKEY_CURRENT_USER\Control Panel\Mouse]:MouseSensitivity, pero esto no tomará efecto hasta el siguiente reinicio de sesión.

O lo haces mediante sendkeys y muestras tu código en VBS para que te podamos ayudar a corregir las pulsaciones que realizaste, o te planteas utilizar un lenguaje capacitado para la tarea, ya que es necesario hacer una llamada a la función SystemParametersInfo de la WinAPI y pasarle el parámetro SPI_SETMOUSESPEED.

Info: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724947%28v=vs.85%29.aspx

Nota: Puedes llamar a la API de Windows desde VBS, pero requiere dependencias adicionales de terceros, y para eso sinceramente es mejor que lo hagas en otro lenguaje (ej: C++, C#, VBNET), es algo muy facil.

Saludos!
6973  Programación / Scripting / Re: [AYUDA][PYTHON] Leer y guardar archivos .exe de forma hexadecimal en python??? en: 22 Agosto 2014, 09:33 am
como se hace para representar al reves (de decimal a string)

Creo que lo que buscas es la función Chr(): https://docs.python.org/2/library/functions.html#chr, o sino la función Str(): https://docs.python.org/2/library/functions.html#str

Código:
>>> f = open('File.txt', 'rb')
>>> data = f.read(1)
>>> print 'str: ' + str(ord(data[0]))
num : 97
>>> print 'char: ' + str(chr(ord(data[0])))
char: a
>>>

como se modifica y reescribe ese codigo en otro archivo o en el mismo???

Aquí tienes ejemplos:

· http://stackoverflow.com/questions/16630789/python-writing-binary-files-bytes
· http://stackoverflow.com/questions/20955543/python-writing-binary
· http://stackoverflow.com/questions/17349918/python-write-string-of-bytes-to-file

Saludos
6974  Programación / Scripting / Re: [AYUDA] Necesito ayuda para crear un batch para emuladores de NES en: 22 Agosto 2014, 08:47 am
Siento decirte que en Batch no es posible, no es una herramienta cualificada para esa tarea, al igual que tampoco es VBS (lo menciono porque es un lenguaje al que se suele recurrir desde Batch para extender las funcionalidad de este)

Debes utilizar cualquier otro lenguaje que esté capacitado para registrar una tecla de acceso rápida (System Global-Hotkey).

EDITO:

Por ejemplo en VB.NET


Saludos!
6975  Programación / Scripting / Re: ¿COMO HACER QUE UN *.bat EXCRIBA UN ARCHIVO DE TEXTO SEGUN LOS DATOS DEL *.bat? en: 22 Agosto 2014, 05:43 am
.bat ... contabilidad
Mala elección, batch es un "lenguaje" (entre comillas) para la automatización de tareas cotidianas, no para el desarrollo de programas complejos como de contabilidad.


Citar
¡no se como hacer que el programa cree el archivo de texto con los datos que se le dio
Muestra tu código.

Saludos!
6976  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 21 Agosto 2014, 13:58 pm
Unos métodos de uso genérico para utilizar la librería IconLib ( http://www.codeproject.com/Articles/16178/IconLib-Icons-Unfolded-MultiIcon-and-Windows-Vista ) para crear iconos o leer las capas de un icono.

PD: Hay que modificar un poco el source (escrito en C#) para permitir la creación de iconos de 512 x 512 (es facil, busquen un if con "256" y añadan el valor "512" a la enumeración de formatos de iconos), pero por otro lado no hay ningún problema para leer este tamaño de icono sin realizar modificaciones.



Código
  1.    ' Create Icon
  2.    ' By Elektro
  3.    '
  4.    ' Usage Examples:
  5.    '
  6.    ' Dim IconFile As IconLib.SingleIcon = CreateIcon("C:\Image.ico", IconLib.IconOutputFormat.All)
  7.    ' For Each IconLayer As IconLib.IconImage In IconFile
  8.    '     PictureBox1.BackgroundImage = IconLayer.Icon.ToBitmap
  9.    '     Debug.WriteLine(IconLayer.Icon.Size.ToString)
  10.    '     Application.DoEvents()
  11.    '     Threading.Thread.Sleep(750)
  12.    ' Next IconLayer
  13.    '
  14.    ''' <summary>
  15.    ''' Creates an icon with the specified image.
  16.    ''' </summary>
  17.    ''' <param name="imagefile">Indicates the image.</param>
  18.    ''' <param name="format">Indicates the icon format.</param>
  19.    ''' <returns>IconLib.SingleIcon.</returns>
  20.    Public Function CreateIcon(ByVal imagefile As String,
  21.                               Optional ByVal format As IconLib.IconOutputFormat =
  22.                                                        IconLib.IconOutputFormat.All) As IconLib.SingleIcon
  23.  
  24.        Dim sIcon As IconLib.SingleIcon = New IconLib.MultiIcon().Add("Icon1")
  25.        sIcon.CreateFrom(imagefile, format)
  26.  
  27.        Return sIcon
  28.  
  29.    End Function
  30.  
  31.    ' Get Icon-Layers
  32.    ' By Elektro
  33.    '
  34.    ' Usage Examples:
  35.    '
  36.    ' For Each IconLayer As IconLib.IconImage In GetIconLayers("C:\Image.ico")
  37.    '     PictureBox1.BackgroundImage = IconLayer.Icon.ToBitmap
  38.    '     Debug.WriteLine(IconLayer.Icon.Size.ToString)
  39.    '     Application.DoEvents()
  40.    '     Threading.Thread.Sleep(750)
  41.    ' Next IconLayer
  42.    '
  43.    ''' <summary>
  44.    ''' Gets all the icon layers inside an icon file.
  45.    ''' </summary>
  46.    ''' <param name="iconfile">Indicates the icon file.</param>
  47.    ''' <returns>IconLib.SingleIcon.</returns>
  48.    Public Function GetIconLayers(ByVal iconfile As String) As IconLib.SingleIcon
  49.  
  50.        Dim mIcon As IconLib.MultiIcon = New IconLib.MultiIcon()
  51.        mIcon.Load(iconfile)
  52.  
  53.        Return mIcon.First
  54.  
  55.    End Function
  56.  
6977  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Compartan aquí sus snippets) en: 21 Agosto 2014, 13:03 pm
Una class para ordenar los items de un listview según la columna:



Código
  1. ' ***********************************************************************
  2. ' Author           : Elektro
  3. ' Last Modified On : 08-20-2014
  4. ' ***********************************************************************
  5. ' <copyright file="ListView Column-Sorter.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Usage Examples "
  11.  
  12. 'Public Class ListViewColumnSorter_TestForm : Inherits form
  13. '
  14. '    ''' <summary>
  15. '    ''' The listview to sort.
  16. '    ''' </summary>
  17. '    Private WithEvents LV As New ListView
  18. '
  19. '    ''' <summary>
  20. '    ''' The 'ListViewColumnSorter' instance.
  21. '    ''' </summary>
  22. '    Private Sorter As New ListViewColumnSorter
  23. '
  24. '    ''' <summary>
  25. '    ''' Initializes a new instance of the <see cref="ListViewColumnSorter_TestForm"/> class.
  26. '    ''' </summary>
  27. '    Public Sub New()
  28. '
  29. '        ' This call is required by the designer.
  30. '        InitializeComponent()
  31. '
  32. '        With LV ' Set the Listview properties.
  33. '
  34. '            ' Set the sorter, our 'ListViewColumnSorter'.
  35. '            .ListViewItemSorter = Sorter
  36. '
  37. '            ' The sorting default direction.
  38. '            .Sorting = SortOrder.Ascending
  39. '
  40. '            ' Set the default sort-modifier.
  41. '            Sorter.SortModifier = ListViewColumnSorter.SortModifiers.SortByText
  42. '
  43. '            ' Add some columns.
  44. '            .Columns.Add("Text").Tag = ListViewColumnSorter.SortModifiers.SortByText
  45. '            .Columns.Add("Numbers").Tag = ListViewColumnSorter.SortModifiers.SortByNumber
  46. '            .Columns.Add("Dates").Tag = ListViewColumnSorter.SortModifiers.SortByDate
  47. '
  48. '            ' Adjust the column sizes.
  49. '            For Each col As ColumnHeader In LV.Columns
  50. '                col.Width = 100I
  51. '            Next
  52. '
  53. '            ' Add some items.
  54. '            .Items.Add("hello").SubItems.AddRange({"1", "11/11/2000"})
  55. '            .Items.Add("yeehaa!").SubItems.AddRange({"2", "11-11-2000"})
  56. '            .Items.Add("El3ktr0").SubItems.AddRange({"10", "9/9/1999"})
  57. '            .Items.Add("wow").SubItems.AddRange({"100", "21/08/2014"})
  58. '
  59. '            ' Visual-Style things.
  60. '            .Dock = DockStyle.Fill
  61. '            .View = View.Details
  62. '            .FullRowSelect = True
  63. '
  64. '        End With
  65. '
  66. '        With Me ' Set the Form properties.
  67. '
  68. '            .Size = New Size(400, 200)
  69. '            .FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
  70. '            .MaximizeBox = False
  71. '            .StartPosition = FormStartPosition.CenterScreen
  72. '            .Text = "ListViewColumnSorter TestForm"
  73. '
  74. '        End With
  75. '
  76. '        ' Add the Listview to UI.
  77. '        Me.Controls.Add(LV)
  78. '
  79. '    End Sub
  80. '
  81. '    ''' <summary>
  82. '    ''' Handles the 'ColumnClick' event of the 'ListView1' control.
  83. '    ''' </summary>
  84. '    Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As ColumnClickEventArgs) _
  85. '    Handles LV.ColumnClick
  86. '
  87. '        ' Dinamycaly sets the sort-modifier to sort the column by text, number, or date.
  88. '        Sorter.SortModifier = sender.columns(e.Column).tag
  89. '
  90. '        ' Determine whether clicked column is already the column that is being sorted.
  91. '        If e.Column = Sorter.Column Then
  92. '
  93. '            ' Reverse the current sort direction for this column.
  94. '            If Sorter.Order = SortOrder.Ascending Then
  95. '                Sorter.Order = SortOrder.Descending
  96. '
  97. '            Else
  98. '                Sorter.Order = SortOrder.Ascending
  99. '
  100. '            End If ' Sorter.Order
  101. '
  102. '        Else
  103. '
  104. '            ' Set the column number that is to be sorted, default to ascending.
  105. '            Sorter.Column = e.Column
  106. '            Sorter.Order = SortOrder.Ascending
  107. '
  108. '        End If ' e.Column
  109. '
  110. '        ' Perform the sort with these new sort options.
  111. '        sender.Sort()
  112. '
  113. '    End Sub
  114. '
  115. 'End Class
  116.  
  117. #End Region
  118.  
  119. #Region " Imports "
  120.  
  121. Imports System.Text.RegularExpressions
  122. Imports System.ComponentModel
  123.  
  124. #End Region
  125.  
  126. #Region " ListView Column-Sorter "
  127.  
  128. ''' <summary>
  129. ''' Performs a sorting comparison.
  130. ''' </summary>
  131. Public Class ListViewColumnSorter : Implements IComparer
  132.  
  133. #Region " Objects "
  134.  
  135.    '''' <summary>
  136.    '''' Indicates the comparer instance.
  137.    '''' </summary>
  138.    Private Comparer As Object = New TextComparer
  139.  
  140. #End Region
  141.  
  142. #Region " Properties "
  143.  
  144.    ''' <summary>
  145.    ''' Gets or sets the number of the column to which to apply the sorting operation (Defaults to '0').
  146.    ''' </summary>
  147.    Public Property Column As Integer
  148.        Get
  149.            Return Me._Column
  150.        End Get
  151.        Set(ByVal value As Integer)
  152.            Me._Column = value
  153.        End Set
  154.    End Property
  155.    Private _Column As Integer = 0I
  156.  
  157.    ''' <summary>
  158.    ''' Gets or sets the order of sorting to apply.
  159.    ''' </summary>
  160.    Public Property Order As SortOrder
  161.        Get
  162.            Return Me._Order
  163.        End Get
  164.        Set(ByVal value As SortOrder)
  165.            Me._Order = value
  166.        End Set
  167.    End Property
  168.    Private _Order As SortOrder = SortOrder.None
  169.  
  170.    ''' <summary>
  171.    ''' Gets or sets the sort modifier.
  172.    ''' </summary>
  173.    ''' <value>The sort modifier.</value>
  174.    Public Property SortModifier As SortModifiers
  175.        Get
  176.            Return Me._SortModifier
  177.        End Get
  178.        Set(ByVal value As SortModifiers)
  179.            Me._SortModifier = value
  180.        End Set
  181.    End Property
  182.    Private _SortModifier As SortModifiers = SortModifiers.SortByText
  183.  
  184. #End Region
  185.  
  186. #Region " Enumerations "
  187.  
  188.    ''' <summary>
  189.    ''' Specifies a comparison result.
  190.    ''' </summary>
  191.    Public Enum ComparerResult As Integer
  192.  
  193.        ''' <summary>
  194.        ''' 'X' is equals to 'Y'.
  195.        ''' </summary>
  196.        Equals = 0I
  197.  
  198.        ''' <summary>
  199.        ''' 'X' is less than 'Y'.
  200.        ''' </summary>
  201.        Less = -1I
  202.  
  203.        ''' <summary>
  204.        ''' 'X' is greater than 'Y'.
  205.        ''' </summary>
  206.        Greater = 1I
  207.  
  208.    End Enum
  209.  
  210.    ''' <summary>
  211.    ''' Indicates a Sorting Modifier.
  212.    ''' </summary>
  213.    Public Enum SortModifiers As Integer
  214.  
  215.        ''' <summary>
  216.        ''' Treats the values &#8203;&#8203;as text.
  217.        ''' </summary>
  218.        SortByText = 0I
  219.  
  220.        ''' <summary>
  221.        ''' Treats the values &#8203;&#8203;as numbers.
  222.        ''' </summary>
  223.        SortByNumber = 1I
  224.  
  225.        ''' <summary>
  226.        ''' Treats valuesthe values &#8203;&#8203;as dates.
  227.        ''' </summary>
  228.        SortByDate = 2I
  229.  
  230.    End Enum
  231.  
  232. #End Region
  233.  
  234. #Region " Private Methods "
  235.  
  236.    ''' <summary>
  237.    ''' Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
  238.    ''' </summary>
  239.    ''' <param name="x">The first object to compare.</param>
  240.    ''' <param name="y">The second object to compare.</param>
  241.    ''' <returns>
  242.    ''' A signed integer that indicates the relative values of <paramref name="x"/> and <paramref name="y"/>,
  243.    ''' 0: <paramref name="x"/> equals <paramref name="y"/>.
  244.    ''' Less than 0: <paramref name="x"/> is less than <paramref name="y"/>.
  245.    ''' Greater than 0: <paramref name="x"/> is greater than <paramref name="y"/>.
  246.    ''' </returns>
  247.    Private Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
  248.  
  249.        Dim CompareResult As ComparerResult = ComparerResult.Equals
  250.        Dim LVItemX, LVItemY As ListViewItem
  251.  
  252.        ' Cast the objects to be compared
  253.        LVItemX = DirectCast(x, ListViewItem)
  254.        LVItemY = DirectCast(y, ListViewItem)
  255.  
  256.        Dim strX As String = If(Not LVItemX.SubItems.Count <= Me._Column,
  257.                               LVItemX.SubItems(Me._Column).Text,
  258.                               Nothing)
  259.  
  260.        Dim strY As String = If(Not LVItemY.SubItems.Count <= Me._Column,
  261.                                LVItemY.SubItems(Me._Column).Text,
  262.                                Nothing)
  263.  
  264.        Dim listViewMain As ListView = LVItemX.ListView
  265.  
  266.        ' Calculate correct return value based on object comparison
  267.        If listViewMain.Sorting <> SortOrder.Ascending AndAlso listViewMain.Sorting <> SortOrder.Descending Then
  268.  
  269.            ' Return '0' to indicate they are equal
  270.            Return ComparerResult.Equals
  271.  
  272.        End If
  273.  
  274.        If Me._SortModifier.Equals(SortModifiers.SortByText) Then
  275.  
  276.            ' Compare the two items
  277.            If LVItemX.SubItems.Count <= Me._Column AndAlso LVItemY.SubItems.Count <= Me._Column Then
  278.                CompareResult = Me.Comparer.Compare(Nothing, Nothing)
  279.  
  280.            ElseIf LVItemX.SubItems.Count <= Me._Column AndAlso LVItemY.SubItems.Count > Me._Column Then
  281.                CompareResult = Me.Comparer.Compare(Nothing, strY)
  282.  
  283.            ElseIf LVItemX.SubItems.Count > Me._Column AndAlso LVItemY.SubItems.Count <= Me._Column Then
  284.                CompareResult = Me.Comparer.Compare(strX, Nothing)
  285.  
  286.            Else
  287.                CompareResult = Me.Comparer.Compare(strX, strY)
  288.  
  289.            End If
  290.  
  291.        Else ' Me._SortModifier IsNot 'SortByText'
  292.  
  293.            Select Case Me._SortModifier
  294.  
  295.                Case SortModifiers.SortByNumber
  296.                    If Me.Comparer.GetType <> GetType(NumericComparer) Then
  297.                        Me.Comparer = New NumericComparer
  298.                    End If
  299.  
  300.                Case SortModifiers.SortByDate
  301.                    If Me.Comparer.GetType <> GetType(DateComparer) Then
  302.                        Me.Comparer = New DateComparer
  303.                    End If
  304.  
  305.                Case Else
  306.                    If Me.Comparer.GetType <> GetType(TextComparer) Then
  307.                        Me.Comparer = New TextComparer
  308.                    End If
  309.  
  310.            End Select
  311.  
  312.            CompareResult = Comparer.Compare(strX, strY)
  313.  
  314.        End If ' Me._SortModifier.Equals(...)
  315.  
  316.        ' Calculate correct return value based on object comparison
  317.        If Me._Order = SortOrder.Ascending Then
  318.            ' Ascending sort is selected, return normal result of compare operation
  319.            Return CompareResult
  320.  
  321.        ElseIf Me._Order = SortOrder.Descending Then
  322.            ' Descending sort is selected, return negative result of compare operation
  323.            Return (-CompareResult)
  324.  
  325.        Else
  326.            ' Return '0' to indicate they are equal
  327.            Return 0I
  328.  
  329.        End If ' Me._Order = ...
  330.  
  331.    End Function
  332.  
  333. #End Region
  334.  
  335. #Region " Hidden Methods "
  336.  
  337.    ''' <summary>
  338.    ''' Serves as a hash function for a particular type.
  339.    ''' </summary>
  340.    <EditorBrowsable(EditorBrowsableState.Never)>
  341.    Public Shadows Sub GetHashCode()
  342.    End Sub
  343.  
  344.    ''' <summary>
  345.    ''' Determines whether the specified System.Object instances are considered equal.
  346.    ''' </summary>
  347.    <EditorBrowsable(EditorBrowsableState.Never)>
  348.    Public Shadows Sub Equals()
  349.    End Sub
  350.  
  351.    ''' <summary>
  352.    ''' Gets the System.Type of the current instance.
  353.    ''' </summary>
  354.    ''' <returns>The exact runtime type of the current instance.</returns>
  355.    <EditorBrowsable(EditorBrowsableState.Never)>
  356.    Public Shadows Function [GetType]()
  357.        Return Me.GetType
  358.    End Function
  359.  
  360.    ''' <summary>
  361.    ''' Returns a String that represents the current object.
  362.    ''' </summary>
  363.    <EditorBrowsable(EditorBrowsableState.Never)>
  364.    Public Shadows Sub ToString()
  365.    End Sub
  366.  
  367. #End Region
  368.  
  369. End Class
  370.  
  371. #End Region
  372.  
  373. #Region " Comparers "
  374.  
  375. #Region " Text "
  376.  
  377. ''' <summary>
  378. ''' Performs a text comparison.
  379. ''' </summary>
  380. Public Class TextComparer : Inherits CaseInsensitiveComparer
  381.  
  382. #Region " Enumerations "
  383.  
  384.    ''' <summary>
  385.    ''' Specifies a comparison result.
  386.    ''' </summary>
  387.    Public Enum ComparerResult As Integer
  388.  
  389.        ''' <summary>
  390.        ''' 'X' is equals to 'Y'.
  391.        ''' </summary>
  392.        Equals = 0I
  393.  
  394.        ''' <summary>
  395.        ''' 'X' is less than 'Y'.
  396.        ''' </summary>
  397.        Less = -1I
  398.  
  399.        ''' <summary>
  400.        ''' 'X' is greater than 'Y'.
  401.        ''' </summary>
  402.        Greater = 1I
  403.  
  404.    End Enum
  405.  
  406. #End Region
  407.  
  408. #Region " Methods "
  409.  
  410.    ''' <summary>
  411.    ''' Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
  412.    ''' </summary>
  413.    ''' <param name="x">The first object to compare.</param>
  414.    ''' <param name="y">The second object to compare.</param>
  415.    ''' <returns>
  416.    ''' A signed integer that indicates the relative values of <paramref name="x"/> and <paramref name="y"/>,
  417.    ''' 0: <paramref name="x"/> equals <paramref name="y"/>.
  418.    ''' Less than 0: <paramref name="x"/> is less than <paramref name="y"/>.
  419.    ''' Greater than 0: <paramref name="x"/> is greater than <paramref name="y"/>.
  420.    ''' </returns>
  421.    Friend Shadows Function Compare(ByVal x As Object, ByVal y As Object) As Integer
  422.  
  423.        ' Null parsing.
  424.        If x Is Nothing AndAlso y Is Nothing Then
  425.            Return ComparerResult.Equals ' X is equals to Y.
  426.  
  427.        ElseIf x Is Nothing AndAlso y IsNot Nothing Then
  428.            Return ComparerResult.Less ' X is less than Y.
  429.  
  430.        ElseIf x IsNot Nothing AndAlso y Is Nothing Then
  431.            Return ComparerResult.Greater ' X is greater than Y.
  432.  
  433.        End If
  434.  
  435.        ' String parsing:
  436.        If (TypeOf x Is String) AndAlso (TypeOf y Is String) Then ' True and True
  437.            Return [Enum].Parse(GetType(ComparerResult),
  438.                                MyBase.Compare(x, y))
  439.  
  440.        ElseIf (TypeOf x Is String) AndAlso Not (TypeOf y Is String) Then ' True and False
  441.            Return ComparerResult.Greater ' X is greater than Y.
  442.  
  443.        ElseIf Not (TypeOf x Is String) AndAlso (TypeOf y Is String) Then ' False and True
  444.            Return ComparerResult.Less ' X is less than Y.
  445.  
  446.        Else ' False and False
  447.            Return ComparerResult.Equals
  448.  
  449.        End If
  450.  
  451.    End Function
  452.  
  453. #End Region
  454.  
  455. End Class
  456.  
  457. #End Region
  458.  
  459. #Region " Numeric "
  460.  
  461. ''' <summary>
  462. ''' Performs a numeric comparison.
  463. ''' </summary>
  464. Public Class NumericComparer : Implements IComparer
  465.  
  466. #Region " Enumerations "
  467.  
  468.    ''' <summary>
  469.    ''' Specifies a comparison result.
  470.    ''' </summary>
  471.    Public Enum ComparerResult As Integer
  472.  
  473.        ''' <summary>
  474.        ''' 'X' is equals to 'Y'.
  475.        ''' </summary>
  476.        Equals = 0I
  477.  
  478.        ''' <summary>
  479.        ''' 'X' is less than 'Y'.
  480.        ''' </summary>
  481.        Less = -1I
  482.  
  483.        ''' <summary>
  484.        ''' 'X' is greater than 'Y'.
  485.        ''' </summary>
  486.        Greater = 1I
  487.  
  488.    End Enum
  489.  
  490. #End Region
  491.  
  492. #Region " Methods "
  493.  
  494.    ''' <summary>
  495.    ''' Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
  496.    ''' </summary>
  497.    ''' <param name="x">The first object to compare.</param>
  498.    ''' <param name="y">The second object to compare.</param>
  499.    ''' <returns>
  500.    ''' A signed integer that indicates the relative values of <paramref name="x"/> and <paramref name="y"/>,
  501.    ''' 0: <paramref name="x"/> equals <paramref name="y"/>.
  502.    ''' Less than 0: <paramref name="x" /> is less than <paramref name="y"/>.
  503.    ''' Greater than 0: <paramref name="x"/> is greater than <paramref name="y"/>.
  504.    ''' </returns>
  505.    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
  506.    Implements IComparer.Compare
  507.  
  508.        ' Null parsing.
  509.        If x Is Nothing AndAlso y Is Nothing Then
  510.            Return ComparerResult.Equals ' X is equals to Y.
  511.  
  512.        ElseIf x Is Nothing AndAlso y IsNot Nothing Then
  513.            Return ComparerResult.Less ' X is less than Y.
  514.  
  515.        ElseIf x IsNot Nothing AndAlso y Is Nothing Then
  516.            Return ComparerResult.Greater ' X is greater than Y.
  517.  
  518.        End If
  519.  
  520.        ' The single variables to parse the text.
  521.        Dim SingleX, SingleY As Single
  522.  
  523.        ' Single parsing:
  524.        If Single.TryParse(x, SingleX) AndAlso Single.TryParse(y, SingleY) Then ' True and True
  525.            Return [Enum].Parse(GetType(ComparerResult),
  526.                                SingleX.CompareTo(SingleY))
  527.  
  528.        ElseIf Single.TryParse(x, SingleX) AndAlso Not Single.TryParse(y, SingleY) Then ' True and False
  529.            Return ComparerResult.Greater ' X is greater than Y.
  530.  
  531.        ElseIf Not Single.TryParse(x, SingleX) AndAlso Single.TryParse(y, SingleY) Then ' False and True
  532.            Return ComparerResult.Less ' X is less than Y.
  533.  
  534.        Else ' False and False
  535.            Return [Enum].Parse(GetType(ComparerResult),
  536.                                x.ToString.CompareTo(y.ToString))
  537.  
  538.        End If
  539.  
  540.    End Function
  541.  
  542. #End Region
  543.  
  544. End Class
  545.  
  546. #End Region
  547.  
  548. #Region " Date "
  549.  
  550. ''' <summary>
  551. ''' Performs a date comparison.
  552. ''' </summary>
  553. Public Class DateComparer : Implements IComparer
  554.  
  555. #Region " Enumerations "
  556.  
  557.    ''' <summary>
  558.    ''' Specifies a comparison result.
  559.    ''' </summary>
  560.    Public Enum ComparerResult As Integer
  561.  
  562.        ''' <summary>
  563.        ''' 'X' is equals to 'Y'.
  564.        ''' </summary>
  565.        Equals = 0I
  566.  
  567.        ''' <summary>
  568.        ''' 'X' is less than 'Y'.
  569.        ''' </summary>
  570.        Less = -1I
  571.  
  572.        ''' <summary>
  573.        ''' 'X' is greater than 'Y'.
  574.        ''' </summary>
  575.        Greater = 1I
  576.  
  577.    End Enum
  578.  
  579. #End Region
  580.  
  581. #Region " Methods "
  582.  
  583.    ''' <summary>
  584.    ''' Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
  585.    ''' </summary>
  586.    ''' <param name="x">The first object to compare.</param>
  587.    ''' <param name="y">The second object to compare.</param>
  588.    ''' <returns>
  589.    ''' A signed integer that indicates the relative values of <paramref name="x"/> and <paramref name="y"/>,
  590.    ''' 0: <paramref name="x"/> equals <paramref name="y"/>.
  591.    ''' Less than 0: <paramref name="x"/> is less than <paramref name="y"/>.
  592.    ''' Greater than 0: <paramref name="x"/> is greater than <paramref name="y"/>.
  593.    ''' </returns>
  594.    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
  595.  
  596.        ' Null parsing.
  597.        If x Is Nothing AndAlso y Is Nothing Then
  598.            Return ComparerResult.Equals ' X is equals to Y.
  599.  
  600.        ElseIf x Is Nothing AndAlso y IsNot Nothing Then
  601.            Return ComparerResult.Less ' X is less than Y.
  602.  
  603.        ElseIf x IsNot Nothing AndAlso y Is Nothing Then
  604.            Return ComparerResult.Greater ' X is greater than Y.
  605.  
  606.        End If
  607.  
  608.        ' The Date variables to parse the text.
  609.        Dim DateX, DateY As Date
  610.  
  611.        ' Date parsing:
  612.        If Date.TryParse(x, DateX) AndAlso Date.TryParse(y, DateY) Then ' True and True
  613.            Return [Enum].Parse(GetType(ComparerResult),
  614.                                DateX.CompareTo(DateY))
  615.  
  616.        ElseIf Date.TryParse(x, DateX) AndAlso Not Date.TryParse(y, DateY) Then ' True and False
  617.            Return ComparerResult.Greater ' X is greater than Y.
  618.  
  619.        ElseIf Not Date.TryParse(x, DateX) AndAlso Date.TryParse(y, DateY) Then ' False and True
  620.            Return ComparerResult.Less ' X is less than Y.
  621.  
  622.        Else ' False and False
  623.            Return [Enum].Parse(GetType(ComparerResult),
  624.                                x.ToString.CompareTo(y.ToString))
  625.  
  626.        End If
  627.  
  628.    End Function
  629.  
  630. #End Region
  631.  
  632. End Class
  633.  
  634. #End Region
  635.  
  636. #End Region
6978  Media / Multimedia / Re: Video .mp4 borroso en: 21 Agosto 2014, 10:53 am
se puede ver claro pero en una ventana que rebasa la pantalla de mi monitor, y cuando trato de reducirlo un poco para adecuarla a la pantalla la imagen se distorsiona.

¿Así que a mayor resolución menor "distorsión"?,
me parece que podría ser un problema de mala configuración del driver de salida que utilizas en el reproductor, o del renderizador que usas por defecto, o un problema de ambos.

Mi pregunta antes de proseguir, ¿tienes instalado algún pack de codecs? (te puedes imaginar mi respuesta en caso de que si que tengas instalado alguno).

Si dices que el VLC es el que menos te distoriona el video entonces ve a las opciones de la aplicación, y busca las configuraciones del driver de salida y del renderizador, aplica esa misma configuración a los reproductores que se te vean mal (en caso de que permitan configurar esos parámetros claro).

Si en el reproductor que te funciona "mal" puedes configurar el driver de salida, escoje "Direct3D", y para el renderizador, prueba con "VMR9 (modo ventana)" o lee aquí  ↠ Choosing the Right Video Renderer

Saludos!
6979  Programación / .NET (C#, VB.NET, ASP) / Re: Mis malas combinaciones :( en: 21 Agosto 2014, 10:22 am
porque no me salen los números que he puesto para combinar ?

Por esto:
Citar
Código
  1. For Num As Integer = IndexCounter To (FixedValues.Count) Step NumStep ' 1 to 30 Step 3
  2.  
  3.               Combo.Add(Num)
  4.               ...

Estás tomando el número de la variable num en lugar de tomar un item de la colección FixedValues, se puede decir que esto ha sido un fallo mio porque como ya sabes en ese ejemplo usé una secuencia ordenada del 1 al 30, así que se me pasó por alto ese detalle al desordenar la secuencia xD.

Prueba a ver si este es el resultado que quieres obtener:
Combo.Add(FixedValues(NumStep * LenCounter))
Edito: o lo que viene a ser lo mismo:

Código
  1. Combo.Add(FixedValues(Num - 1))

Explico:
Para generar la primera combinación con los números que has mostrado, daría saltos de '3' para tomar estas posiciones:
Código:
{ 1, , , 22, , , 66, , , 20, } 
+ un número aleatorio aleatorio del rango que especificaste EDITO: del rango de 'RandomValues', para dejarlo claro.

Saludos
6980  Programación / .NET (C#, VB.NET, ASP) / Re: Problema con Visual Studio 2010 en: 21 Agosto 2014, 10:01 am
¿Puedes compartir el proyecto para echarle un vistazo?, te pediría que subieses un video del problema pero creo que no sería tan util como lo primero.

Saludos!
Páginas: 1 ... 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 [698] 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 ... 1254
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines