| |

VerySource

 Forgot password?
 Register
Search
Author: hataki

Help: vb save data to Excel, is there a quick way! ~

[Copy link]

0

Threads

16

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-7-28 15:45:01
| Show all posts
Range(1, 1).CopyFromRecordset
----------Excel's own method is very fast.
Reply

Use magic Report

0

Threads

16

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-7-29 14:00:01
| Show all posts
An even example, the method of adding data to the excel file is added to the display function of data collection! ! ! For the poster's reference!

Sub ShowDigitProc()
    Screen.MousePointer = vbHourglass''''''''''' means waiting state
    Dim xls As Object'Excel format output data
    Set xls = CreateObject("Excel.Application")
    xls.Visible = True
    xls.Caption = "Four Signals"
    Set xlbook = xls.Workbooks.Add'Excel format output data
    Dim Row As Integer
    Dim Col As Integer
    Dim i, j As Integer
    Dim channelpot As Integer
    Dim ch0(511), ch1(511), ch2(511), ch3(511) As Single
  
    channelpot = (4096-(4096 Mod ChannelCount))'The prototype is: channelpot = (8192-(8192 Mod ChannelCount))
    For i = 0 To ChannelCount-1
        s$ = s$ + "| CH" + Str$(Hist_Header.FirstChannel + i)
    Next
    Grid.FormatString = s$
    s$ = ";"
   
     For i = 0 + m_Offset To ((channelpot / ChannelCount)-1 + m_Offset)
    s$ = s$ + "|" + Str$(i)
    Next
     Grid.FormatString = s$
      'Open "D:\05.txt" For Output As #1''Read data in text format
    For Row = 1 To ((4096-(4096 Mod ChannelCount)) / ChannelCount)
        Col = 0''''''''''''''''''''''''''Data can be accessed!!!!!!!!!!!!!
            Grid.TextMatrix(Row, Col + 1) = Format(((((InRegionUser((Row-1) * ChannelCount + Col) Xor&H2000) And&H3FFF)-&H2000) * PoltvalueChange) / 1000, "#.00000")
            ch0(511) = Grid.TextMatrix(Row, Col + 1)
            ch0(511) = Val(ch0(511))
            Text3.Text = ch0(511)
            xls.Cells(Row, 1).Value = ch0(511)'Excel format output data
        Col = 1''''''''''''''''''''''''''Data can be accessed!!!!!!!!!!!!!
            Grid.TextMatrix(Row, Col + 1) = Format(((((InRegionUser((Row-1) * ChannelCount + Col) Xor&H2000) And&H3FFF)-&H2000) * PoltvalueChange) / 1000, "#.00000")
            ch1(511) = Grid.TextMatrix(Row, Col + 1)
            ch1(511) = Val(ch1(511))
            Text4.Text = ch1(511)
            xls.Cells(Row, 2).Value = ch1(511)'Excel format output data
        Col = 2''''''''''''''''''''''''''Data can be accessed!!!!!!!!!!!!!
            Grid.TextMatrix(Row, Col + 1) = Format(((((InRegionUser((Row-1) * ChannelCount + Col) Xor&H2000) And&H3FFF)-&H2000) * PoltvalueChange) / 1000, "#.00000")
            ch2(511) = Grid.TextMatrix(Row, Col + 1)
            ch2(511) = Val(ch2(511))
            Text5.Text = ch2(511)
            xls.Cells(Row, 3).Value = ch2(511)'Excel format output data
       Col = 3''''''''''''''''''''''''''Data can be accessed!!!!!!!!!!!!!
          Grid.TextMatrix(Row, Col + 1) = Format(((((InRegionUser((Row-1) * ChannelCount + Col) Xor&H2000) And&H3FFF)-&H2000) * PoltvalueChange) / 1000, "#.00000")
           ch3(511) = Grid.TextMatrix(Row, Col + 1)
           Text6.Text = ch3(511)
           xls.Cells(Row, 4).Value = ch3(511)'Excel format output data
      'Write #1, ch0(511), ch1(511), ch2(511), ch3(511)''Read data in text format
    'Draw_Click
   'Picture2.PSet (ch0(511), ch2(511)), RGB(255, 0, 255)
       Next
       'Close #1''Read data in text format
    Screen.MousePointer = vbDefault''''''''''''' means that the shape is determined by the object
End Sub
Reply

Use magic Report

2

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-8-9 08:30:02
| Show all posts
Finally, I used the txt method to solve it. The speed is super fast. Thank you very much for your help.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list