zoukankan      html  css  js  c++  java
  • Excel programming (C# + VBA) Part 1

    Excel programming (C# + VBA)

    Here is the secario of a full process of solution to use excel to submit information.

    •    Clarify the requirement and create the Excel template (VBA)
    • Generate an Excel template to fill with source data (C#)
    • Download the template from web site (C# + ASP.NET)
    • Fill in the template and verified the data via VBA (VBA)
    • Upload the template (Web) (ASP.NET)
    • Import data in Excel Template to database (C#)

    1.      Setp 1 Create the Excel Template based on requirement

    a.       Clarify the requirement

    b.      Create hidden template sheet

                                                                   i.      Clarify the data type in each cell, fill in type (user input/list validation or a pop form) and the lock property.

    c.       Create hidden data source sheet

                                                                   i.      Clarify the source data in each column

                                                                 ii.      Create named range for list validation (If the data is already known)

    d.      Create Summary, Filling Sheet

                                                                   i.      Set the layout, add validation button and Add new button

    e.      VBA programming to add list validation or auto-filling 

        rng.Validation.Add xlValidateList, xlValidAlertStop, xlBetween, "=SpecialOfferType"
        rng.Validation.IgnoreBlank 
    = True
        rng.Validation.InCellDropdown 
    = True
        

    f.        VBA programming to select data in pop form

                With frmChoose
                    .CCodeColumn 
    = "AB"
                    .CNameColumn 
    = "B"
                    .CRow 
    = Target.Row
                    .CCodeSourceColumn 
    = "B"
                    .CNameSourceColumn 
    = "C"
                    .CKeyWords 
    = Me.Cells(iRow, iColumn).Text
                    .Caption 
    = Me.Cells(iRow, iColumn - 1)
                    
    Set .CWorksheet = Application.ActiveSheet
                    
    Set .CSourceWorksheet = sourceSheet
                    .Show
                
    End With

    In frmChoose, when the Ok button is clicked:

            CWorksheet.Unprotect Password
            
            n 
    = 2
            
    If (CSourceWorksheet Is NothingThen
                name 
    = wsDataSource.Range(CNameSourceColumn & n).Text
            
    Else
                name 
    = CSourceWorksheet.Range(CNameSourceColumn & n).Text
            
    End If
            
            
    While (name <> "")
                
    If name = lstSelected.List(lstSelected.ListIndex) Then
                    
    If (CSourceWorksheet Is NothingThen
                        code 
    = wsDataSource.Range(CCodeSourceColumn & n).Text
                    
    Else
                        code 
    = CSourceWorksheet.Range(CCodeSourceColumn & n).Text
                    
    End If
                
    End If
                
                n 
    = n + 1
                
    If (CSourceWorksheet Is NothingThen
                    name 
    = wsDataSource.Range(CNameSourceColumn & n).Text
                
    Else
                    name 
    = CSourceWorksheet.Range(CNameSourceColumn & n).Text
                
    End If
            
    Wend
            
            
    If (CNameColumn <> ""Then
                CWorksheet.Range(CNameColumn 
    & CRow).Value2 = lstSelected.List(lstSelected.ListIndex)
            
    End If
            
            
    If (CCodeColumn <> ""Then
                CWorksheet.Range(CCodeColumn 
    & CRow).Value2 = code
            
    End If
            
            CWorksheet.Protect Password
            

    g.       VBA programming to validate the data filled in every sheets

              If Not CheckDateType(ws.Cells(i, 2).Value) Then
                    bCheck 
    = False
                    
    MsgBox ws.Cells(i, 1).Value & "ÄÚÊäÈëµÄ²»ÊÇÓÐЧʱ¼ä"
                    ws.Activate
                    ws.Cells(i, 
    2).Select
                    
    Exit Sub
              
    End If
    .....


    Function CheckNumberic(sourceString As StringAs Boolean
        
    Dim bOk As Boolean
        bOk 
    = True
        
    If sourceString <> "" And Not IsNumeric(sourceString) Then
            bOk 
    = False
        
    End If
        
        CheckNumberic 
    = bOk
    End Function


    Function CheckDateType(sourceString As StringAs Boolean
        
    Dim bOk As Boolean
        bOk 
    = False
        
    If sourceString <> "" And IsDate(sourceString) Then
            bOk 
    = True
        
    End If
        
        CheckDateType 
    = bOk
        
    End Function

     

    2.  

  • 相关阅读:
    面试6 在c#中如何声明一个类不能被继承
    面试5 如何理解静态变量,局部变量,全局变量
    面试4 你在什么情况下会用到虚方法?它与接口有什么不同
    面试3 不用系统自带的方法将字符串类型123456转换为值类型
    面试2 递归的算法求1,1,2,3,5,8.......的第30位数是多少,然后求这些数的和.
    面试1 SQL SERVER 查询第20行到30之间的数据
    ubuntu安装nginx
    ubuntu上使用ufw配置管理防火墙
    ubuntu上安装docker
    ubuntu上使用vim编辑文本内容
  • 原文地址:https://www.cnblogs.com/lyrix/p/973366.html
Copyright © 2011-2022 走看看