怎么用java转置csv,如何转置一组列并将输出另存为CSV

I have a long set of information in columns, sometimes hundreds of rows (This is being generated via VBA). I need to transpose this AND save it as a CSV (as excel would run out of columns).

A screenshot of the table is attached.

cGK0I.png

Any help is appreciated in advance.

Question has been answered in two different ways. Am sure it will be valuable to many other people.

解决方案

You take some code to export to CSV, such as from this answer

How to create a separate CSV file from VBA?

and just change the order you write to the file. E.g. write the column before writing the row

Sub WriteFile()

Dim ColNum As Integer

Dim Line As String

Dim LineValues() As Variant

Dim OutputFileNum As Integer

Dim PathName As String

Dim RowNum As Integer

Dim SheetValues() As Variant

PathName = Application.ActiveWorkbook.Path

OutputFileNum = FreeFile

Open PathName & "\Test.csv" For Output Lock Write As #OutputFileNum

'Print #OutputFileNum, "Field1" & "," & "Field2"

SheetValues = Sheets("RawData").Range("A1:C249").Value

Dim RowMax

RowMax = UBound(SheetValues)

Dim ColMax

ColMax = 3

ReDim LineValues(1 To RowMax)

For ColNum = 1 To ColMax

For RowNum = 1 To RowMax

LineValues(RowNum) = SheetValues(RowNum, ColNum)

Next

Line = Join(LineValues, ",")

Print #OutputFileNum, Line

Next

Close OutputFileNum

End Sub

Hopefully that is a good enough to get you going.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值