eeror:

f:\tools\excel-to-text.cs(41,51): error CS1501: No overload for method 'Open' takes '3' arguments
f:\tools\Microsoft.Office.Interop.Excel.dll: (Location of symbol related to previous error)




using System;
using System.IO;
using System.Collections.Generic;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;

class Program
{
    [STAThread]
    static void Main()
    {
        // Initialize Excel interop
        Excel.Application excelApp = new Excel.Application();
        excelApp.Visible = false;

        // Open folder dialog to select folder containing Excel files
        using (var folderDialog = new FolderBrowserDialog())
        {
            if (folderDialog.ShowDialog() == DialogResult.OK)
            {
                string outputFilePath = Path.Combine(folderDialog.SelectedPath, "output.tsv");
                using (StreamWriter writer = new StreamWriter(outputFilePath, false, System.Text.Encoding.UTF8))
                {
                    // Get all Excel files in the selected folder that match the specified patterns
                    string[] excelFiles = Directory.GetFiles(folderDialog.SelectedPath, "*.xls*");
                    var filteredFiles = new List<string>();

                    foreach (string file in excelFiles)
                    {
                        // Check if the file matches the specified patterns
                        if (file.EndsWith("-m29.xlsx", StringComparison.OrdinalIgnoreCase) ||
                            file.EndsWith("-m29.xls", StringComparison.OrdinalIgnoreCase))
                        {
                            filteredFiles.Add(file);
                        }
                    }

                    foreach (string file in filteredFiles)
                    {
                        // Open the workbook
                        Excel.Workbook workbook = excelApp.Workbooks.Open(file, Type.Missing, true);
                        try
                        {
                            // Loop through each worksheet in the workbook
                            foreach (Excel.Worksheet worksheet in workbook.Worksheets)
                            {
                                Excel.Range usedRange = worksheet.UsedRange;

                                // Start reading from the second row (ignoring header)
                                int rowCount = usedRange.Rows.Count;
                                int columnCount = usedRange.Columns.Count;

                                for (int row = 2; row <= rowCount; row++) // Start from row 2
                                {
                                    string[] rowData = new string[columnCount];
                                    for (int col = 1; col <= columnCount; col++)
                                    {
                                        // Read cell value and handle potential nulls
                                        object cellValue = (usedRange.Cells[row, col] as Excel.Range).Value2;
                                        rowData[col - 1] = cellValue != null ? cellValue.ToString() : string.Empty;
                                    }
                                    // Write the row data as TSV
                                    writer.WriteLine(string.Join("\t", rowData));
                                }
                            }
                        }
                        finally
                        {
                            // Close the workbook
                            workbook.Close(false, Type.Missing, Type.Missing);
                        }
                    }
  
  
  
  
  
  
                    // foreach (string file in filteredFiles)
                    // {
                    //     // Open the workbook
                    //     Excel.Workbook workbook = excelApp.Workbooks.Open(file);
                    //     try
                    //     {
                    //         // Loop through each worksheet in the workbook
                    //         foreach (Excel.Worksheet worksheet in workbook.Worksheets)
                    //         {
                    //             Excel.Range usedRange = worksheet.UsedRange;

                    //             // Start reading from the second row (ignoring header)
                    //             int rowCount = usedRange.Rows.Count;
                    //             int columnCount = usedRange.Columns.Count;

                    //             for (int row = 2; row <= rowCount; row++) // Start from row 2
                    //             {
                    //                 string[] rowData = new string[columnCount];
                    //                 for (int col = 1; col <= columnCount; col++)
                    //                 {
                    //                     // Read cell value and handle potential nulls
                    //                     object cellValue = (usedRange.Cells[row, col] as Excel.Range).Value2;
                    //                     rowData[col - 1] = cellValue != null ? cellValue.ToString() : string.Empty;
                    //                 }
                    //                 // Write the row data as TSV
                    //                 writer.WriteLine(string.Join("\t", rowData));
                    //             }
                    //         }
                    //     }
                    //     finally
                    //     {
                    //         // Close the workbook
                    //         workbook.Close(false);
                    //     }
                    // }
                }
                MessageBox.Show("Data has been written to " + outputFilePath);
            }
        }

        // Clean up Excel interop
        excelApp.Quit();
        System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
    }
}