我正在将数据从sql server导出到excel,但输出结果已到,但数据在excel中是水平打印的。但是我想在垂直方向打印数据可以帮助我解决此问题...下面的代码
public void ExportTable(string query, string sheetName)
{
SqlConnection myConnection = new SqlConnection(CONNECTION_STR);
SqlDataReader myReader = null;
try
{
Excel.Worksheet oSheet = (Excel.Worksheet)workbook.Sheets.Add(Missing.Value, Missing.Value, 1, Excel.XlSheetType.xlWorksheet);
oSheet.Name = sheetName;
previousWorksheet = oSheet;
myConnection.Open();
SqlCommand myCommand = new SqlCommand(query, myConnection);
myReader = myCommand.ExecuteReader();
int columnCount = myReader.FieldCount;
int rowCounter = 3;
while (myReader.Read())
{
for (int n = 0; n < columnCount; n++)
{
addData(oSheet, rowCounter, n + 1, myReader[myReader.GetName(n)].ToString());
}
rowCounter++;
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}