本帖最后由 buyiyang 于 2023-3-27 12:48 编辑
bat- #@&cls&powershell -sta "gc '%~f0'|out-string|iex"&pause&exit
- $csvFileName = "1.csv"
- $numberOfRows = 1000000
- $numberOfColumns = 5000
-
- $csharpCode = @"
- using System.IO;
- using System.Text;
- public static class GenerateCSV {
- public static void GenerateCSVFile(string fileName, int numberOfRows, int numberOfColumns) {
- using (var streamWriter = new StreamWriter(fileName, false, Encoding.UTF8)) {
- for (int row = 1; row <= numberOfRows; row++) {
- StringBuilder lineBuilder = new StringBuilder();
- for (int col = row; col < row + numberOfColumns; col++) {
- if (col > row) {
- lineBuilder.Append(",");
- }
- lineBuilder.Append(col.ToString());
- }
- streamWriter.WriteLine(lineBuilder.ToString());
- }
- }
- }
- }
- "@
-
- Add-Type -TypeDefinition $csharpCode -Language CSharp
- [GenerateCSV]::GenerateCSVFile($csvFileName, $numberOfRows, $numberOfColumns)
- Write-Host "$csvFileName OK"
复制代码
|