如何在不打开的情况下创建Excel文件的副本

时间:2022-10-24 13:47:48

What is the command to create a copy of an Excel file without opening it using VB.NET?

在不使用VB.NET打开的情况下创建Excel文件副本的命令是什么?

4 个解决方案

#2


Let's keep it VB-centric: My.Computer.FileSystem.CopyFile()

让它以VB为中心:My.Computer.FileSystem.CopyFile()

#3


The parm 'true' in the copy method says to overwrite any existing file so it doesn't bomb out.

复制方法中的parm“true”表示覆盖任何现有文件,因此不会弹出。

Imports System.IO
Module Module1
    Sub Main()
        Dim originalFile As String = "c:\work\myExcelFile.xls"
        Dim copyOfOriginalFile As String = "c:\work\myExcelFileCopy.xls"

        If File.Exists(originalFile) Then
            System.IO.File.Copy(originalFile, copyOfOriginalFile, True) 
        Else
            Console.WriteLine("{0} does not exist", originalFile)
        End If
    End Sub
End Module

#4


If System.IO.File.Exists("Directory1" & "File.xlsx") Then
   My.Computer.File.System.CopyFile("Directory1" & "File.xlsx", 
                                     "Directory2" & "File.xlsx", True)
End If

#1


#2


Let's keep it VB-centric: My.Computer.FileSystem.CopyFile()

让它以VB为中心:My.Computer.FileSystem.CopyFile()

#3


The parm 'true' in the copy method says to overwrite any existing file so it doesn't bomb out.

复制方法中的parm“true”表示覆盖任何现有文件,因此不会弹出。

Imports System.IO
Module Module1
    Sub Main()
        Dim originalFile As String = "c:\work\myExcelFile.xls"
        Dim copyOfOriginalFile As String = "c:\work\myExcelFileCopy.xls"

        If File.Exists(originalFile) Then
            System.IO.File.Copy(originalFile, copyOfOriginalFile, True) 
        Else
            Console.WriteLine("{0} does not exist", originalFile)
        End If
    End Sub
End Module

#4


If System.IO.File.Exists("Directory1" & "File.xlsx") Then
   My.Computer.File.System.CopyFile("Directory1" & "File.xlsx", 
                                     "Directory2" & "File.xlsx", True)
End If