简体   繁体   English

如何使用VB.NET中的电子表格光源将一个Excel文件复制到另一个文件?

[英]How to copy one Excel file to another using spreadsheet light in VB.NET?

I have a code wherein I am taking two files. 我有一个代码,其中我正在采取两个文件。 Both are Excel files and I need to copy one file to another. 两者都是Excel文件,我需要将一个文件复制到另一个文件。 The number of rows and columns in the files are dynamic. 文件中的行数和列数是动态的。

sFile is the source file and sFile1 is the destination file. sFile是源文件, sFile1是目标文件。 I need to know the number of rows in source file to run a for loop when am copying it to destination file. 我需要知道源文件中的行数,以便在将其复制到目标文件时运行for循环。

The code is below: 代码如下:

Dim shtlight As New SLDocument(sFile1) 
Dim lrow As Integer 
Dim lcol As Integer 
Dim sflie = Environment.Directory & "\Data.xls" 
lrow = 2  
Dim shtlight1 As New SLDocument(sFile1) 

For each row in sfile1 
    for column in sfile1 'code here to set value next next

I want help in running this for loop, don't know how to set the upper bound as no of rows and columns in file is dynamic. 我想要帮助运行这个for循环,不知道如何设置上限,因为文件中的行和列没有动态。

Can someone help please? 有人可以帮忙吗? I am using phone so format might not be correct. 我正在使用手机,因此格式可能不正确。 :( :(

As I mentioned in the comments above, I have never worked with SpreadsheetLight . 正如我在上面的评论中提到的,我从未使用过SpreadsheetLight I just downloaded SpreadsheetLight and experimented with it. 我刚刚下载了SpreadsheetLight并进行了实验。

To get the last row you need to use this 要获得最后一行,您需要使用它

Imports DocumentFormat.OpenXML
Imports DocumentFormat.OpenXML.Spreadsheet
Imports SpreadsheetLight

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim sl As New SLDocument("C:\Users\Siddharth\Desktop\Tester.xlsx", "Sheet1")
        MessageBox.Show (sl.GetWorksheetStatistics.EndRowIndex)
    End Sub
End Class

在此输入图像描述

Note 注意

For someone who is novice like me to SpreadsheetLight and would like to experiment. 对于像我这样的新手SpreadsheetLight而且想要试验的人。

  1. Reference set to DocumentFormat.OpenXml.dll ( Open XML SDK 2.0 ). 参考设置为DocumentFormat.OpenXml.dll( Open XML SDK 2.0 )。 Can be downloaded from Here . 可以从这里下载。 It didn't work with Open XML SDK 2.5 for me and I didn't put too much into it to find out to why... 它对我来说不适用于Open XML SDK 2.5 ,我没有过多介绍它为什么......

  2. Reference set to SpreadsheetLight. 参考设置为SpreadsheetLight。 Can be downloaded from Here 可以从这里下载

Above code is tested on VS 2013 以上代码在VS 2013上进行了测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM