从excel文件中select填充行并填充列(具有值的行和列)

这是一个简单的问题,但我没有成功做到这一点。 我需要使用值在行和列上循环运行 – select值。

我写了一个函数来做到这一点,但随着debugging,我看到行计数是1048576,文件只有32行的值(同列发生)

function码:

let functionParseXmlToCsv (xmlFile:string , excelFormatFile:string , excelPath:string) = let xlApp = new Excel.ApplicationClass() let xlWorkBookInput = xlApp.Workbooks.Open(excelPath + DateTime.Today.ToString("yyyy_dd_MM")+".xlsx") let listOfRows = ResizeArray<string>() for tabs in 1 .. xlWorkBookInput.Worksheets.Count do let listOfCells = ResizeArray<string>() let xlWorkSheetInput = xlWorkBookInput.Worksheets.[tabs] :?> Excel.Worksheet let filePath = excelPath + DateTime.Today.ToString("yyyy_dd_MM")+"_"+xlWorkSheetInput.Name+".csv" //let csvFile = File.Create(filePath) use csvFile = StreamWriter(filePath, true) for rowNumber in 1 .. xlWorkSheetInput.Rows.Count do for columnNumber in 1.. xlWorkSheetInput.Columns.Count do let cell = xlWorkSheetInput.Cells.[rowNumber,columnNumber] let value = string cell listOfCells.Add(value) let s = String.Join(", ", listOfCells) csvFile.WriteLine(s) File.Exists(excelPath + DateTime.Today.ToString("yyyy_dd_MM")+".xlsx") 

有人可以帮我吗?

尝试如果UsedRange修复您的问题。 所以改变你的行/列循环

 for rowNumber in 1 .. xlWorkSheetInput.UsedRange.Rows.Count do 

 for columnNumber in 1.. xlWorkSheetInput.UsedRange.Columns.Count do