Aspose.Cells 구성 요 소 를 사용 하여 Excel 파일 인 스 턴 스 생 성
물론 더 복잡 한 것 은 셀 을 통합 하 는 방법 인 Public void Merge(int firstRow,int firstColumn,int totalRows,int totalColumns)를 통 해 이 루어 질 수 있다.
구현 방식:
1.우선"Aspose.Cells.dll"에 대한 인용 을 추가 해 야 합 니 다.
2.실현 코드 는 다음 과 같다.
//
Workbook workbook = new Workbook(); //
Worksheet sheet = workbook.Worksheets[0]; //
Cells cells = sheet.Cells;//
Style style = workbook.Styles[workbook.Styles.Add()];//
#region
//
style.HorizontalAlignment = TextAlignmentType.Center;//
style.Font.Name = " ";//
style.Font.Size = 18;//
style.Font.IsBold = true;//
cells.Merge(0, 0, 1, 12); //
cells[0, 0].PutValue(" "); //
cells[0, 0].SetStyle(style); //
cells.SetRowHeight(0, 28); //
//
style.HorizontalAlignment = TextAlignmentType.Left;
style.Font.Size = 11;
style.Font.IsBold = false;
cells.Merge(1, 0, 1, 7);
cells[1, 0].PutValue(String.Format(" :{0} {1}",DateTime.Now.AddDays(-1).ToString("yyyy MM dd "),DateTime.Now.ToString("yyyy MM dd ")));
cells[1, 0].SetStyle(style);
cells.SetRowHeight(1, 20);
//
style.HorizontalAlignment = TextAlignmentType.Right;
style.Font.Size = 11;
style.Font.IsBold = false;
cells.Merge(1, 7, 1, 5);
cells[1, 7].PutValue(String.Format(" :{0}", DateTime.Now.ToString("yyyy MM dd ")));
cells[1, 7].SetStyle(style);
cells.SetRowHeight(1, 20);
#endregion
#region
#region
//
style.HorizontalAlignment = TextAlignmentType.Center;
cells[2, 0].PutValue(" ");
cells[2, 0].SetStyle(style);
cells.SetRowHeight(2, 20);
cells.SetColumnWidthPixel(0, 38);
//
cells[2, 1].PutValue(" ");
cells[2, 1].SetStyle(style);
cells.SetColumnWidthPixel(1, 77);
//
cells[2, 2].PutValue(" ");
cells[2, 2].SetStyle(style);
cells.SetColumnWidthPixel(2, 107);
//
cells[2, 3].PutValue(" ");
cells[2, 3].SetStyle(style);
cells.SetColumnWidthPixel(3, 69);
//
cells[2, 4].PutValue(" ");
cells[2, 4].SetStyle(style);
cells.SetColumnWidthPixel(4, 71);
//
cells[2, 5].PutValue(" ");
cells[2, 5].SetStyle(style);
cells.SetColumnWidthPixel(5, 71);
//
cells[2, 6].PutValue(" ");
cells[2, 6].SetStyle(style);
cells.SetColumnWidthPixel(6, 114);
// 、
cells[2, 7].PutValue(" 、 ");
cells[2, 7].SetStyle(style);
cells.SetColumnWidthPixel(7, 104);
//
cells[2, 8].PutValue(" ");
cells[2, 8].SetStyle(style);
cells.SetColumnWidthPixel(8, 255);
//
cells[2, 9].PutValue(" ");
cells[2, 9].SetStyle(style);
cells.SetColumnWidthPixel(9, 72);
//
cells[2, 10].PutValue(" ");
cells[2, 10].SetStyle(style);
cells.SetColumnWidthPixel(10, 72);
//
cells[2, 11].PutValue(" ");
cells[2, 11].SetStyle(style);
cells.SetColumnWidthPixel(11, 255);
#endregion
#endregion
System.IO.MemoryStream ms = workbook.SaveToStream();//
byte[] bt = ms.ToArray();
workbook.Save(@"E:\test.xls");//
}
3.생 성 된 Excel 은 디스크 에 저장 할 수도 있 고 웹 페이지 에서 흐 르 는 방식 으로 다운로드 할 수도 있 습 니 다.
//
System.IO.MemoryStream ms = workbook.SaveToStream();//
byte[] bt = ms.ToArray();
string fileName = " " + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";//
//
Response.ContentType = "application/vnd.ms-excel";
//
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bt);
Response.Flush();
Response.End();
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Aspose 를 사용 하여 office 파일 을 Html 파일 로 변환 하고 파일 생 성Aspose 를 사용 하여 office 파일 을 Html 파일 로 변환 하 는 방법 은 다음 과 같 습 니 다. PPT 파일 이 생 성 된 html 에 인 코딩 인식 오류 가 발생 하여 브 라 우 저 웹 페이지 가 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.