당신은 당신의 데이터 집합을 한 후에는 객체로 변환 할 수 있습니다 [,]와에 삽입 : 당신이 저장 강제하려면
Response.ContentType = "application/vnd.ms-excel";
, 당신은 다음과 같은 일을 할 것입니다 Excel 문서. 그런 다음 문서를 디스크에 저장하고 사용자에게 스트리밍 할 수 있습니다.
//write the column headers
for (int cIndex = 1; cIndex < 1 + columns; cIndex++)
sheet.Cells.set_Item(4, cIndex, data.Columns[cIndex - 1].Caption);
if (rows > 0)
{
//select the range where the data will be pasted
Range r = sheet.get_Range(sheet.Cells[5, 1], sheet.Cells[5 + (rows - 1), columns]);
//Convert the datatable to an object array
object[,] workingValues = new object[rows, columns];
for (int rIndex = 0; rIndex < rows; rIndex++)
for (int cIndex = 0; cIndex < columns; cIndex++)
workingValues[rIndex, cIndex] = data.Rows[rIndex][cIndex].ToString();
r.Value2 = workingValues;
}
Excel을 열고 수동으로 생성 한 것처럼 정상적인 Excel 파일을 생성하지 않는다는 사실을 명심하십시오.이 파일은 html 파일입니다. –