Merge multiple CSV into one without using Excel.Application












0















I created a PowerShell script that allows me to merge multiple .CSV into one .XLSX file.



It works well on my computer:



$path = "C:UsersFrancescoDesktopCSVResults*"
$csvs = Get-ChildItem $path -Include *.csv
$y = $csvs.Count
Write-Host "Detected the following CSV files: ($y)"
Write-Host " "$csvs.Name"`n"
$outputfilename = "Final Registry Results"
Write-Host Creating: $outputfilename
$excelapp = New-Object -ComObject Excel.Application
$excelapp.SheetsInNewWorkbook = $csvs.Count
$xlsx = $excelapp.Workbooks.Add()
for ($i=1;$i -le $y;$i++) {
$worksheet = $xlsx.Worksheets.Item($i)
$worksheet.Name = $csvs[$i-1].Name
$file = (Import-Csv $csvs[$i-1].FullName)
$file | ConvertTo-Csv -Delimiter "`t" -NoTypeInformation | clip
$worksheet.Cells.Item(1).PasteSpecial() | Out-Null
}

$output = "C:UsersFrancescoDesktopCSVResultsResults.xlsx"
$xlsx.SaveAs($output)
$excelapp.Quit()


The problem is that I need to run this on several servers and servers are well known for not having Office installed so I cannot use Excel.Application.



Is there a way to merge multiple CSV into one CSV or XLSX without using Excel.Application and saving each CSV into a different sheet?










share|improve this question




















  • 2





    what have you tried so far? do the columns from the csv files differ or are they the same? did you even search (stackoverflow.com/questions/27892957/…)? there are multiple results on SO

    – Guenther Schmitz
    Nov 6 '18 at 10:51






  • 2





    CSV doesn't support multiple sheets in the same file. You're looking for the ImportExcel module. Requests for tool recommendations are off-topic, though, as you should know.

    – Ansgar Wiechers
    Nov 6 '18 at 10:53













  • Possible duplicate of Merging multiple CSV files into one using PowerShell

    – James C.
    Nov 6 '18 at 12:11











  • Thank you @AnsgarWiechers, I think your reply is the right one. Unfortunately there is no way to archive so. Please post your reply so and I will label it as the right one. I didn't know that requesting tool recommendation was off-topic, but by the way I'm not doing so.

    – Francesco Mantovani
    Nov 6 '18 at 20:04











  • Thank you @JamesC. but it's not a duplicate of that question. But maybe it's a slightly duplicate of this question: stackoverflow.com/questions/29615196/… but that was about C#... but I found the answer there... apparetly a .CSV is a mere .TXT

    – Francesco Mantovani
    Nov 6 '18 at 20:07
















0















I created a PowerShell script that allows me to merge multiple .CSV into one .XLSX file.



It works well on my computer:



$path = "C:UsersFrancescoDesktopCSVResults*"
$csvs = Get-ChildItem $path -Include *.csv
$y = $csvs.Count
Write-Host "Detected the following CSV files: ($y)"
Write-Host " "$csvs.Name"`n"
$outputfilename = "Final Registry Results"
Write-Host Creating: $outputfilename
$excelapp = New-Object -ComObject Excel.Application
$excelapp.SheetsInNewWorkbook = $csvs.Count
$xlsx = $excelapp.Workbooks.Add()
for ($i=1;$i -le $y;$i++) {
$worksheet = $xlsx.Worksheets.Item($i)
$worksheet.Name = $csvs[$i-1].Name
$file = (Import-Csv $csvs[$i-1].FullName)
$file | ConvertTo-Csv -Delimiter "`t" -NoTypeInformation | clip
$worksheet.Cells.Item(1).PasteSpecial() | Out-Null
}

$output = "C:UsersFrancescoDesktopCSVResultsResults.xlsx"
$xlsx.SaveAs($output)
$excelapp.Quit()


The problem is that I need to run this on several servers and servers are well known for not having Office installed so I cannot use Excel.Application.



Is there a way to merge multiple CSV into one CSV or XLSX without using Excel.Application and saving each CSV into a different sheet?










share|improve this question




















  • 2





    what have you tried so far? do the columns from the csv files differ or are they the same? did you even search (stackoverflow.com/questions/27892957/…)? there are multiple results on SO

    – Guenther Schmitz
    Nov 6 '18 at 10:51






  • 2





    CSV doesn't support multiple sheets in the same file. You're looking for the ImportExcel module. Requests for tool recommendations are off-topic, though, as you should know.

    – Ansgar Wiechers
    Nov 6 '18 at 10:53













  • Possible duplicate of Merging multiple CSV files into one using PowerShell

    – James C.
    Nov 6 '18 at 12:11











  • Thank you @AnsgarWiechers, I think your reply is the right one. Unfortunately there is no way to archive so. Please post your reply so and I will label it as the right one. I didn't know that requesting tool recommendation was off-topic, but by the way I'm not doing so.

    – Francesco Mantovani
    Nov 6 '18 at 20:04











  • Thank you @JamesC. but it's not a duplicate of that question. But maybe it's a slightly duplicate of this question: stackoverflow.com/questions/29615196/… but that was about C#... but I found the answer there... apparetly a .CSV is a mere .TXT

    – Francesco Mantovani
    Nov 6 '18 at 20:07














0












0








0








I created a PowerShell script that allows me to merge multiple .CSV into one .XLSX file.



It works well on my computer:



$path = "C:UsersFrancescoDesktopCSVResults*"
$csvs = Get-ChildItem $path -Include *.csv
$y = $csvs.Count
Write-Host "Detected the following CSV files: ($y)"
Write-Host " "$csvs.Name"`n"
$outputfilename = "Final Registry Results"
Write-Host Creating: $outputfilename
$excelapp = New-Object -ComObject Excel.Application
$excelapp.SheetsInNewWorkbook = $csvs.Count
$xlsx = $excelapp.Workbooks.Add()
for ($i=1;$i -le $y;$i++) {
$worksheet = $xlsx.Worksheets.Item($i)
$worksheet.Name = $csvs[$i-1].Name
$file = (Import-Csv $csvs[$i-1].FullName)
$file | ConvertTo-Csv -Delimiter "`t" -NoTypeInformation | clip
$worksheet.Cells.Item(1).PasteSpecial() | Out-Null
}

$output = "C:UsersFrancescoDesktopCSVResultsResults.xlsx"
$xlsx.SaveAs($output)
$excelapp.Quit()


The problem is that I need to run this on several servers and servers are well known for not having Office installed so I cannot use Excel.Application.



Is there a way to merge multiple CSV into one CSV or XLSX without using Excel.Application and saving each CSV into a different sheet?










share|improve this question
















I created a PowerShell script that allows me to merge multiple .CSV into one .XLSX file.



It works well on my computer:



$path = "C:UsersFrancescoDesktopCSVResults*"
$csvs = Get-ChildItem $path -Include *.csv
$y = $csvs.Count
Write-Host "Detected the following CSV files: ($y)"
Write-Host " "$csvs.Name"`n"
$outputfilename = "Final Registry Results"
Write-Host Creating: $outputfilename
$excelapp = New-Object -ComObject Excel.Application
$excelapp.SheetsInNewWorkbook = $csvs.Count
$xlsx = $excelapp.Workbooks.Add()
for ($i=1;$i -le $y;$i++) {
$worksheet = $xlsx.Worksheets.Item($i)
$worksheet.Name = $csvs[$i-1].Name
$file = (Import-Csv $csvs[$i-1].FullName)
$file | ConvertTo-Csv -Delimiter "`t" -NoTypeInformation | clip
$worksheet.Cells.Item(1).PasteSpecial() | Out-Null
}

$output = "C:UsersFrancescoDesktopCSVResultsResults.xlsx"
$xlsx.SaveAs($output)
$excelapp.Quit()


The problem is that I need to run this on several servers and servers are well known for not having Office installed so I cannot use Excel.Application.



Is there a way to merge multiple CSV into one CSV or XLSX without using Excel.Application and saving each CSV into a different sheet?







excel powershell csv export-to-csv excel.application






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 6 '18 at 10:56









Ansgar Wiechers

141k13126185




141k13126185










asked Nov 6 '18 at 10:34









Francesco MantovaniFrancesco Mantovani

548614




548614








  • 2





    what have you tried so far? do the columns from the csv files differ or are they the same? did you even search (stackoverflow.com/questions/27892957/…)? there are multiple results on SO

    – Guenther Schmitz
    Nov 6 '18 at 10:51






  • 2





    CSV doesn't support multiple sheets in the same file. You're looking for the ImportExcel module. Requests for tool recommendations are off-topic, though, as you should know.

    – Ansgar Wiechers
    Nov 6 '18 at 10:53













  • Possible duplicate of Merging multiple CSV files into one using PowerShell

    – James C.
    Nov 6 '18 at 12:11











  • Thank you @AnsgarWiechers, I think your reply is the right one. Unfortunately there is no way to archive so. Please post your reply so and I will label it as the right one. I didn't know that requesting tool recommendation was off-topic, but by the way I'm not doing so.

    – Francesco Mantovani
    Nov 6 '18 at 20:04











  • Thank you @JamesC. but it's not a duplicate of that question. But maybe it's a slightly duplicate of this question: stackoverflow.com/questions/29615196/… but that was about C#... but I found the answer there... apparetly a .CSV is a mere .TXT

    – Francesco Mantovani
    Nov 6 '18 at 20:07














  • 2





    what have you tried so far? do the columns from the csv files differ or are they the same? did you even search (stackoverflow.com/questions/27892957/…)? there are multiple results on SO

    – Guenther Schmitz
    Nov 6 '18 at 10:51






  • 2





    CSV doesn't support multiple sheets in the same file. You're looking for the ImportExcel module. Requests for tool recommendations are off-topic, though, as you should know.

    – Ansgar Wiechers
    Nov 6 '18 at 10:53













  • Possible duplicate of Merging multiple CSV files into one using PowerShell

    – James C.
    Nov 6 '18 at 12:11











  • Thank you @AnsgarWiechers, I think your reply is the right one. Unfortunately there is no way to archive so. Please post your reply so and I will label it as the right one. I didn't know that requesting tool recommendation was off-topic, but by the way I'm not doing so.

    – Francesco Mantovani
    Nov 6 '18 at 20:04











  • Thank you @JamesC. but it's not a duplicate of that question. But maybe it's a slightly duplicate of this question: stackoverflow.com/questions/29615196/… but that was about C#... but I found the answer there... apparetly a .CSV is a mere .TXT

    – Francesco Mantovani
    Nov 6 '18 at 20:07








2




2





what have you tried so far? do the columns from the csv files differ or are they the same? did you even search (stackoverflow.com/questions/27892957/…)? there are multiple results on SO

– Guenther Schmitz
Nov 6 '18 at 10:51





what have you tried so far? do the columns from the csv files differ or are they the same? did you even search (stackoverflow.com/questions/27892957/…)? there are multiple results on SO

– Guenther Schmitz
Nov 6 '18 at 10:51




2




2





CSV doesn't support multiple sheets in the same file. You're looking for the ImportExcel module. Requests for tool recommendations are off-topic, though, as you should know.

– Ansgar Wiechers
Nov 6 '18 at 10:53







CSV doesn't support multiple sheets in the same file. You're looking for the ImportExcel module. Requests for tool recommendations are off-topic, though, as you should know.

– Ansgar Wiechers
Nov 6 '18 at 10:53















Possible duplicate of Merging multiple CSV files into one using PowerShell

– James C.
Nov 6 '18 at 12:11





Possible duplicate of Merging multiple CSV files into one using PowerShell

– James C.
Nov 6 '18 at 12:11













Thank you @AnsgarWiechers, I think your reply is the right one. Unfortunately there is no way to archive so. Please post your reply so and I will label it as the right one. I didn't know that requesting tool recommendation was off-topic, but by the way I'm not doing so.

– Francesco Mantovani
Nov 6 '18 at 20:04





Thank you @AnsgarWiechers, I think your reply is the right one. Unfortunately there is no way to archive so. Please post your reply so and I will label it as the right one. I didn't know that requesting tool recommendation was off-topic, but by the way I'm not doing so.

– Francesco Mantovani
Nov 6 '18 at 20:04













Thank you @JamesC. but it's not a duplicate of that question. But maybe it's a slightly duplicate of this question: stackoverflow.com/questions/29615196/… but that was about C#... but I found the answer there... apparetly a .CSV is a mere .TXT

– Francesco Mantovani
Nov 6 '18 at 20:07





Thank you @JamesC. but it's not a duplicate of that question. But maybe it's a slightly duplicate of this question: stackoverflow.com/questions/29615196/… but that was about C#... but I found the answer there... apparetly a .CSV is a mere .TXT

– Francesco Mantovani
Nov 6 '18 at 20:07












1 Answer
1






active

oldest

votes


















0














@AnsgarWiechers is right, ImportExcel is powerful and not difficult to use. However for your specific case you can use a more limited approach, using OleDb (or ODBC or ADO) to write to an Excel file like a database. Here is some sample code showing how to write to an Excel file using OleDb.



$provider = 'Microsoft.ACE.OLEDB.12.0'
$dataSource = 'C:usersuserOleDb.xlsb'
$connStr = "Provider=$provider;Data Source=$dataSource;Extended Properties='Excel 12.0;HDR=YES'"
$objConn = [Data.OleDb.OleDbConnection]::new($connStr)
$objConn.Open()

$cmd = $objConn.CreateCommand()

$sheetName = 'Demo'
$cmd.CommandText = 'CREATE TABLE $sheetName (Name TEXT,Age NUMBER)'
$cmd.ExecuteNonQuery()

$cmd.CommandText = "INSERT INTO demo (Name,Age) VALUES ('Adam', 20)"
$cmd.ExecuteNonQuery()

$cmd.CommandText = "INSERT INTO demo (Name,Age) VALUES ('Bob',30)"
$cmd.ExecuteNonQuery()

$cmd.Dispose()
$objConn.Close()
$objConn.Dispose()


You didn't say much about the CSV files you'll be processing. If column data varies, to create the table you'll have to get the attribute (column) names from the CSV header (either by reading the first line of the CSV file, or by enumerating the properties of the first item returned by Import-CSV).



If your CSV files have a large number of lines, writing one line at a time may be slow. In that case using a DataSet and OleDbDataAdapter might improve performance (but I haven't tested). But at that point you might as well use OleDb to read the .csv directly into a DataSet, create a OleDbDataAdapter, set the adapter's InsertCommand property, and finally call the adapters Update method. I don't have time to write and test all that.



This is not intended as a full solution, just a demo of how to use OleDb to write to an Excel file.



Note: I tested this on a server that didn't have Office or Excel installed. The Office data providers pre-installed on that machine were 32-bit, but I was using 64-bit PowerShell. To get 64-bit drivers I installed the Microsoft Access Database Engine 2016 Redistributable and that's what I used for testing.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53170132%2fmerge-multiple-csv-into-one-without-using-excel-application%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    @AnsgarWiechers is right, ImportExcel is powerful and not difficult to use. However for your specific case you can use a more limited approach, using OleDb (or ODBC or ADO) to write to an Excel file like a database. Here is some sample code showing how to write to an Excel file using OleDb.



    $provider = 'Microsoft.ACE.OLEDB.12.0'
    $dataSource = 'C:usersuserOleDb.xlsb'
    $connStr = "Provider=$provider;Data Source=$dataSource;Extended Properties='Excel 12.0;HDR=YES'"
    $objConn = [Data.OleDb.OleDbConnection]::new($connStr)
    $objConn.Open()

    $cmd = $objConn.CreateCommand()

    $sheetName = 'Demo'
    $cmd.CommandText = 'CREATE TABLE $sheetName (Name TEXT,Age NUMBER)'
    $cmd.ExecuteNonQuery()

    $cmd.CommandText = "INSERT INTO demo (Name,Age) VALUES ('Adam', 20)"
    $cmd.ExecuteNonQuery()

    $cmd.CommandText = "INSERT INTO demo (Name,Age) VALUES ('Bob',30)"
    $cmd.ExecuteNonQuery()

    $cmd.Dispose()
    $objConn.Close()
    $objConn.Dispose()


    You didn't say much about the CSV files you'll be processing. If column data varies, to create the table you'll have to get the attribute (column) names from the CSV header (either by reading the first line of the CSV file, or by enumerating the properties of the first item returned by Import-CSV).



    If your CSV files have a large number of lines, writing one line at a time may be slow. In that case using a DataSet and OleDbDataAdapter might improve performance (but I haven't tested). But at that point you might as well use OleDb to read the .csv directly into a DataSet, create a OleDbDataAdapter, set the adapter's InsertCommand property, and finally call the adapters Update method. I don't have time to write and test all that.



    This is not intended as a full solution, just a demo of how to use OleDb to write to an Excel file.



    Note: I tested this on a server that didn't have Office or Excel installed. The Office data providers pre-installed on that machine were 32-bit, but I was using 64-bit PowerShell. To get 64-bit drivers I installed the Microsoft Access Database Engine 2016 Redistributable and that's what I used for testing.






    share|improve this answer






























      0














      @AnsgarWiechers is right, ImportExcel is powerful and not difficult to use. However for your specific case you can use a more limited approach, using OleDb (or ODBC or ADO) to write to an Excel file like a database. Here is some sample code showing how to write to an Excel file using OleDb.



      $provider = 'Microsoft.ACE.OLEDB.12.0'
      $dataSource = 'C:usersuserOleDb.xlsb'
      $connStr = "Provider=$provider;Data Source=$dataSource;Extended Properties='Excel 12.0;HDR=YES'"
      $objConn = [Data.OleDb.OleDbConnection]::new($connStr)
      $objConn.Open()

      $cmd = $objConn.CreateCommand()

      $sheetName = 'Demo'
      $cmd.CommandText = 'CREATE TABLE $sheetName (Name TEXT,Age NUMBER)'
      $cmd.ExecuteNonQuery()

      $cmd.CommandText = "INSERT INTO demo (Name,Age) VALUES ('Adam', 20)"
      $cmd.ExecuteNonQuery()

      $cmd.CommandText = "INSERT INTO demo (Name,Age) VALUES ('Bob',30)"
      $cmd.ExecuteNonQuery()

      $cmd.Dispose()
      $objConn.Close()
      $objConn.Dispose()


      You didn't say much about the CSV files you'll be processing. If column data varies, to create the table you'll have to get the attribute (column) names from the CSV header (either by reading the first line of the CSV file, or by enumerating the properties of the first item returned by Import-CSV).



      If your CSV files have a large number of lines, writing one line at a time may be slow. In that case using a DataSet and OleDbDataAdapter might improve performance (but I haven't tested). But at that point you might as well use OleDb to read the .csv directly into a DataSet, create a OleDbDataAdapter, set the adapter's InsertCommand property, and finally call the adapters Update method. I don't have time to write and test all that.



      This is not intended as a full solution, just a demo of how to use OleDb to write to an Excel file.



      Note: I tested this on a server that didn't have Office or Excel installed. The Office data providers pre-installed on that machine were 32-bit, but I was using 64-bit PowerShell. To get 64-bit drivers I installed the Microsoft Access Database Engine 2016 Redistributable and that's what I used for testing.






      share|improve this answer




























        0












        0








        0







        @AnsgarWiechers is right, ImportExcel is powerful and not difficult to use. However for your specific case you can use a more limited approach, using OleDb (or ODBC or ADO) to write to an Excel file like a database. Here is some sample code showing how to write to an Excel file using OleDb.



        $provider = 'Microsoft.ACE.OLEDB.12.0'
        $dataSource = 'C:usersuserOleDb.xlsb'
        $connStr = "Provider=$provider;Data Source=$dataSource;Extended Properties='Excel 12.0;HDR=YES'"
        $objConn = [Data.OleDb.OleDbConnection]::new($connStr)
        $objConn.Open()

        $cmd = $objConn.CreateCommand()

        $sheetName = 'Demo'
        $cmd.CommandText = 'CREATE TABLE $sheetName (Name TEXT,Age NUMBER)'
        $cmd.ExecuteNonQuery()

        $cmd.CommandText = "INSERT INTO demo (Name,Age) VALUES ('Adam', 20)"
        $cmd.ExecuteNonQuery()

        $cmd.CommandText = "INSERT INTO demo (Name,Age) VALUES ('Bob',30)"
        $cmd.ExecuteNonQuery()

        $cmd.Dispose()
        $objConn.Close()
        $objConn.Dispose()


        You didn't say much about the CSV files you'll be processing. If column data varies, to create the table you'll have to get the attribute (column) names from the CSV header (either by reading the first line of the CSV file, or by enumerating the properties of the first item returned by Import-CSV).



        If your CSV files have a large number of lines, writing one line at a time may be slow. In that case using a DataSet and OleDbDataAdapter might improve performance (but I haven't tested). But at that point you might as well use OleDb to read the .csv directly into a DataSet, create a OleDbDataAdapter, set the adapter's InsertCommand property, and finally call the adapters Update method. I don't have time to write and test all that.



        This is not intended as a full solution, just a demo of how to use OleDb to write to an Excel file.



        Note: I tested this on a server that didn't have Office or Excel installed. The Office data providers pre-installed on that machine were 32-bit, but I was using 64-bit PowerShell. To get 64-bit drivers I installed the Microsoft Access Database Engine 2016 Redistributable and that's what I used for testing.






        share|improve this answer















        @AnsgarWiechers is right, ImportExcel is powerful and not difficult to use. However for your specific case you can use a more limited approach, using OleDb (or ODBC or ADO) to write to an Excel file like a database. Here is some sample code showing how to write to an Excel file using OleDb.



        $provider = 'Microsoft.ACE.OLEDB.12.0'
        $dataSource = 'C:usersuserOleDb.xlsb'
        $connStr = "Provider=$provider;Data Source=$dataSource;Extended Properties='Excel 12.0;HDR=YES'"
        $objConn = [Data.OleDb.OleDbConnection]::new($connStr)
        $objConn.Open()

        $cmd = $objConn.CreateCommand()

        $sheetName = 'Demo'
        $cmd.CommandText = 'CREATE TABLE $sheetName (Name TEXT,Age NUMBER)'
        $cmd.ExecuteNonQuery()

        $cmd.CommandText = "INSERT INTO demo (Name,Age) VALUES ('Adam', 20)"
        $cmd.ExecuteNonQuery()

        $cmd.CommandText = "INSERT INTO demo (Name,Age) VALUES ('Bob',30)"
        $cmd.ExecuteNonQuery()

        $cmd.Dispose()
        $objConn.Close()
        $objConn.Dispose()


        You didn't say much about the CSV files you'll be processing. If column data varies, to create the table you'll have to get the attribute (column) names from the CSV header (either by reading the first line of the CSV file, or by enumerating the properties of the first item returned by Import-CSV).



        If your CSV files have a large number of lines, writing one line at a time may be slow. In that case using a DataSet and OleDbDataAdapter might improve performance (but I haven't tested). But at that point you might as well use OleDb to read the .csv directly into a DataSet, create a OleDbDataAdapter, set the adapter's InsertCommand property, and finally call the adapters Update method. I don't have time to write and test all that.



        This is not intended as a full solution, just a demo of how to use OleDb to write to an Excel file.



        Note: I tested this on a server that didn't have Office or Excel installed. The Office data providers pre-installed on that machine were 32-bit, but I was using 64-bit PowerShell. To get 64-bit drivers I installed the Microsoft Access Database Engine 2016 Redistributable and that's what I used for testing.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 23 '18 at 20:39

























        answered Nov 23 '18 at 11:02









        jimharkjimhark

        4,12711822




        4,12711822






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53170132%2fmerge-multiple-csv-into-one-without-using-excel-application%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...