PdfCopy add footer and merge pdf by itextsharp vb.net

Imports iTextSharp.text.pdf

Imports iTextSharp.text
''' iTextSharp ver = 5.5.6.0
'''-------------------------------------
Public Sub PdfCopyAddFooterAndMergePdf()
        Dim PdfFilePath As String = "C:\temp\test.pdf"
        Dim outputPath As String = "C:\temp\merge.pdf"

        Dim reader As PdfReader = Nothing
        Dim pdfDoc As Document = Nothing
        Dim pdfCpy As PdfCopy = Nothing
        Dim page As PdfImportedPage = Nothing

        Try
            'Read input pdf file
            reader = New PdfReader(PdfFilePath)

            'Create new document and set the size as input pdf size
            pdfDoc = New Document(reader.GetPageSizeWithRotation(1))

            'Create output new pdf
            pdfCpy = New PdfCopy(pdfDoc, New FileStream(outputPath, FileMode.Create))

            pdfDoc.Open()

            Dim pageNumbers As New List(Of Integer)(New Integer() {2, 4, 6, 8})

            For Each pageNum As Integer In pageNumbers
                page = pdfCpy.GetImportedPage(reader, pageNum)

                Dim stamp As PdfCopy.PageStamp = pdfCpy.CreatePageStamp(page)
                Dim uc As PdfContentByte = stamp.GetUnderContent
                Dim footerTable As New PdfPTable(1)
                footerTable.TotalWidth = pdfDoc.PageSize.Width

                'Create new Base Font for japanese text display
                Dim fontPath As String = System.IO.Path.Combine(Environment.GetEnvironmentVariable("windir"), "fonts", "msgothic.ttc")
                Dim footerFont As New Font(BaseFont.CreateFont(fontPath & ",0", BaseFont.IDENTITY_H, True), 10)

                Dim myFooter As New Chunk("Your footer", footerFont)
                Dim footer As New PdfPCell(New Phrase(myFooter))
                footer.Border = Rectangle.NO_BORDER

                footer.HorizontalAlignment = Element.ALIGN_RIGHT
                footerTable.AddCell(footer)

                footerTable.WriteSelectedRows(0, -1, -120, (pdfDoc.BottomMargin + 51), uc)

                'Accept changes                   
                stamp.AlterContents()

                pdfCpy.AddPage(page)
            Next

            pdfDoc.Close()
            reader.Close()
            pdfCpy.Close()

        Catch ex As Exception
            Throw ex
        Finally
            reader = Nothing
            pdfDoc = Nothing
            pdfCpy = Nothing
            page = Nothing
        End Try
    End Sub

Open Illustrator file vb.net

   Public Sub IllustratorOpen()
        Dim illApp = CreateObject("Illustrator.Application")

        Dim FullPath = "C:\temp\testTemp\test.ai"
        With illApp.Open(FullPath)

            .Activate()

            'Check TextFrames
            For Each textFrame As Object In .TextFrames
                MsgBox(textFrame.Contents)
            Next

            'Check Layers
            For Each layer As Object In .Layers
                MsgBox(layer.Name)
                layer.Visible = True
            Next

            'aiDoNotSaveChanges = 2
            .Close(2)
        End With

        illApp.Quit()
        illApp = Nothing

    End Sub

SortStringListLongestToShortest vb.net

Public Sub SortStringListLongestToShortest()
        Dim items As New List(Of String)(New String() {"cat", "mouse", "lion"})

        ' Sort using lambda expression.
        items.Sort(Function(x As String, y As String)
                       Return y.Length.CompareTo(x.Length)
                   End Function)

        For Each element As String In items
            Console.WriteLine(element)
        Next

    End Sub

VBA find excel duplicate row by multiple column value(エクセルの複数列の重複行情報取得)

Option Explicit

Public Sub DuplicateCheck()
    Dim lastRowNum As Integer
 
   'Please change your target column. This sample use B column
   lastRowNum = ActiveSheet.Cells(ActiveSheet.Rows.Count, "B").End(xlUp).Row
 
    Dim rowNum As Integer
 
    Dim ucKeyVal1 As String
    Dim ucKeyVal2 As String
 
    Dim myDictionary As Object
    Set myDictionary = CreateObject("Scripting.Dictionary")
 
    For rowNum = 2 To lastRowNum
        ucKeyVal1 = Cells(rowNum, 2).Value
        ucKeyVal2 = Cells(rowNum, 14).Value
     
        Dim dicVal As String
        dicVal = ucKeyVal1 & ucKeyVal2
     
        If myDictionary.Exists(dicVal) Then
           MsgBox (dicVal)
           Else
           '重複情報登録する
           myDictionary.Add dicVal, dicVal
        End If
    Next

    MsgBox ("Done")

End Sub

How to determine if a File is Hidden VB.NET

    Public Function FileIsHidden(FilePath As String) As Boolean
        If (System.IO.File.GetAttributes(FilePath) And System.IO.FileAttributes.Hidden) = System.IO.FileAttributes.Hidden Then
            Return True
        End If

        Return False

    End Function

Remove excel validation list vb.net

Private Sub DeleteDropDownList()
        Try
            Dim xlApp As New Excel.Application
            xlApp.Visible = False
            xlApp.ScreenUpdating = False
            xlApp.DisplayAlerts = False
 
            'Open book here
            Dim xlBook As Excel.Workbook = xlApp.Workbooks.Open("FullPath")
 
            'Get sheet here
            Dim xlSheet As Excel.Worksheet = xlBook.Worksheets("Sheet1")
 
            'Get data used last row
            Dim lastRow As Integer = xlSheet.Cells.Find("*", SearchOrder:=1, SearchDirection:=2).Row()
 
            'Select the delete data range
            Dim cellRange As String = String.Format("AC{0}:AC{1}", 1, lastRow)
 
            With xlSheet.Range(cellRange).Validation
                .Delete()
                'xlValidateInputOnly=0  xlValidAlertStop = 1 xlBetween = 1
                .Add(Type:=0, AlertStyle:=1, Operator:=1)
                .IgnoreBlank = True
                .InCellDropdown = True
                .InputTitle = ""
                .ErrorTitle = ""
                .InputMessage = ""
                .ErrorMessage = ""
                .ShowInput = True
                .ShowError = True
            End With
 
            xlBook.Save()
            xlSheet = Nothing
            xlBook.Close()
            xlBook = Nothing
 
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

How to Google drive spreadsheet auto backup by the time schedule

STEP-1 : Open your spreadsheet
STEP-2 : Click Tools menu
STEP-3 : Click script editor
STEP-4 : Add this code
-------------------------------------
*Note: Create in your google My Drive a folder name 'Backup' the backup file will save in your Backup folder.
// Make copy of current spreadsheet with backup name.                  
function SpreadSheetBackup() {
 
    // Get current spreadsheet.
    var ss = SpreadsheetApp.getActiveSpreadsheet();
 
    // spreadsheet with date.
    var file = DocsList.getFileById(ss.getId());
 
    var bssName = Utilities.formatDate(new Date(), "GMT""yyyyMMdd");
    var fileCopied = file.makeCopy(bssName);
 
    // Make sure all the formulae have been evaluated...                     
    SpreadsheetApp.flush();
 
    // Go to the (collection) a specified folder
    var folder = DocsList.getFolder('Backup');
    fileCopied.addToFolder(folder);
 
    // and remove it from your root folder                    
    fileCopied.removeFromFolder(DocsList.getRootFolder());
}

-------------------------------------
STEP-5 : Click Resources menu
STEP-6 : Click Current project's triggers
STEP-7 : Select Run 'SpreadSheetBackup'
STEP-8 : Select Events 'Time-driven'



How to get Plain Text of a Word Document using Open XML

 Private Sub btnRun_Click(sender As Object, e As RoutedEventArgsHandles btnRun.Click
        Try
            Dim extTxt As New ExtractText
            Dim extText = extTxt.ReadWordDocument("C:\sample-file.docx")
 
            Using sw As New System.IO.StreamWriter("C:\Sample.txt")
                sw.Write(extText)
            End Using
 
            MessageBox.Show("Done!""Result"MessageBoxButton.OK, MessageBoxImage.Exclamation)
 
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error!"MessageBoxButton.OK, MessageBoxImage.Error)
 
        End Try
    End Sub
------------------------------------------------------------------------------------

Before building the sample , please make sure you have installed Open XML SDK 2.5 

Imports System.Text
Imports DocumentFormat.OpenXml
Imports DocumentFormat.OpenXml.Packaging
 
Public Class ExtractText
   
    ''' <summary> 
    '''  Read Word Document 
    ''' </summary> 
    ''' <returns>Plain Text in document </returns> 
    Public Function ReadWordDocument(filePath As StringAs String
        Dim sb As New StringBuilder()
        ' Open a WordprocessingDocument for editing using the filepath.
        Using wpd As WordprocessingDocument = WordprocessingDocument.Open(filePath, True)
            Dim element As OpenXmlElement = wpd.MainDocumentPart.Document.Body
            If element IsNot Nothing Then sb.Append(GetPlainText(element))
        End Using
 
        Return sb.ToString()
    End Function
 
    ''' <summary> 
    '''  Read Plain Text in all XmlElements of word document 
    ''' </summary> 
    ''' <param name="element">XmlElement in document</param> 
    ''' <returns>Plain Text in XmlElement</returns> 
    Public Function GetPlainText(element As OpenXmlElementAs String
        Dim PlainTextInWord As New StringBuilder()
        For Each section As OpenXmlElement In element.Elements()
            Select Case section.LocalName
                ' Text 
                Case "t"
                    PlainTextInWord.Append(section.InnerText)
                    Exit Select
 
                    ' Carriage return 
                Case "cr""br"
                    ' Page break 
                    PlainTextInWord.Append(Environment.NewLine)
                    Exit Select
 
                    ' Tab 
                Case "tab"
                    PlainTextInWord.Append(vbTab)
                    Exit Select
 
                    ' Paragraph 
                Case "p"
                    PlainTextInWord.Append(GetPlainText(section))
                    PlainTextInWord.AppendLine(Environment.NewLine)
                    Exit Select
                Case Else
 
                    PlainTextInWord.Append(GetPlainText(section))
                    Exit Select
            End Select
        Next
 
        Return PlainTextInWord.ToString()
    End Function 
 
End Class

VB.Net ListBox selected item up down with button

    'Move up
    Private Sub btnUp_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles btnUp.Click
        With Me.ListBox1
            If .SelectedItem Is Nothing Then Exit Sub
 
            'Make sure our item is not the first one on the list.
            If .SelectedIndex > 0 Then
                Dim I = .SelectedIndex - 1
                .Items.Insert(I, .SelectedItem)
                .Items.RemoveAt(.SelectedIndex)
                .SelectedIndex = I
            End If
        End With
    End Sub
 
    'Move down
    Private Sub btnDown_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles btnDown.Click
        With Me.ListBox1
 
            If .SelectedItem Is Nothing Then Exit Sub
 
            'Make sure our item is not the last one on the list.
            If .SelectedIndex < .Items.Count - 1 Then
                'Insert places items above the index you supply, since we want
                'to move it down the list we have to do + 2
                Dim I = .SelectedIndex + 2
                .Items.Insert(I, .SelectedItem)
                .Items.RemoveAt(.SelectedIndex)
                .SelectedIndex = I - 1
            End If
        End With
    End Sub

WPF 4 Datagrid row with UP DOWN button

=========================================XAML Code=========================================
<Window x:Class="DataView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="UpdateGrade" Height="400" Width="400" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
 
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="333*"/>
            <ColumnDefinition Width="61*"/>
        </Grid.ColumnDefinitions>
        
        <DataGrid Name="dgDataView" ItemsSource="{Binding Data}" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single">
 
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Name" Width="150">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
        
        <StackPanel Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Button Name="btnUP" Content="UP" Margin="5"/>
            <Button Name="btnDown" Content="Down" Margin="5"/>
        </StackPanel>
    </Grid>
</Window>

 
=========================================VB Code=========================================

Private Sub btnUP_Click(sender As Object, e As RoutedEventArgsHandles btnUP.Click

        With Me.dgDataView
              If .SelectedItem Is Nothing Then Exit Sub

        Dim listItems As ObservableCollection(Of Item) = Me.dgDataView.ItemsSource
            Dim idx  As Integer = .SelectedIndex             If idx  > 0 Then                 Dim rememberMe As Object = .SelectedItem                 listItems.RemoveAt(idx)                 listItems.Insert(idx - 1, rememberMe)                 Me.dgDataView.ItemsSource = listItems                 .SelectedIndex = idx - 1             End If         End With     End Sub
    Private Sub btnDown_Click(sender As Object, e As RoutedEventArgsHandles btnDown.Click
 
        With Me.dgDataView
              If .SelectedItem Is Nothing Then Exit Sub

        Dim listItems As ObservableCollection(Of GradeItem) = Me.dgDataView.ItemsSource
            'Make sure our item is not the last one on the list.             If .SelectedIndex < .Items.Count - 1 Then                 Dim rememberMe As Object = .SelectedItem                 'Insert places items above the index you supply, since we want                 'to move it down the list we have to do + 2                 Dim idx = .SelectedIndex + 2                 listItems.Insert(idx, rememberMe)                 listItems.RemoveAt(.SelectedIndex)                 Me.dgDataView.ItemsSource = listItems                 .SelectedIndex = idx - 1             End If         End With     End Sub