C# excel 내보내기

2901 단어
 
//  
public void addData()
        {
            //  list excel 
            IList<String> list1 = new List<String>();
            list1.Add(" ");
            IList<String> list2 = new List<String>();
            list2.Add(" ");
            list2.Add(txtSoilThickness1.Text);
            list2.Add(" ");
            list2.Add(txtPitShaftThickness1.Text);
            list2.Add(" ");
            list2.Add(txtSoilSide1.Text);
            list2.Add(" ");
            list2.Add(txtSoilStrength1.Text);
            list2.Add(" ");
            list2.Add(txtSoilRange1.Text);
          
            IList<object> item = new List<object>();
            item.Add(list1);
            item.Add(list2);
            this.ReportToExcel(item, "excel ");

        }

 public void ReportToExcel(IList<object> list, string ReportTitleName)
        {
            string path;
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = " Excel(*.xls)|*.xls";
            sfd.FileName = ReportTitleName;

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                path = sfd.FileName;
                Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();
                Aspose.Cells.Worksheet ws = wb.Worksheets[0];
                Cells cell = ws.Cells;
                string[,] _ReportDt = new string[5, 5];

                //  
                //Aspose.Cells.Range range = cell.CreateRange(0,0,1,5);
                //range.Merge();
                //cell["A1"].PutValue(ReportTitleName);

                ////  
                //cell.SetRowHeight(0,20);

                //  
                //Aspose.Cells.Style style1 = wb.Styles[wb.Styles.Add()];
                //style1.HorizontalAlignment = TextAlignmentType.Center; //  
                //style1.Font.Name = " ";
                //style1.Font.IsBold = true; //  
                //style1.Font.Size = 12; //  
                //  
                //cell["A1"].SetStyle(style1);    //    

                for (int i = 0; i < list.Count; i++)
                {
                    IList<String> item = (List<String>)list[i];
                    for (int j = 0; j < item.Count; j++)
                    {
                        cell[i, j].PutValue(item[j]);
                    }

                }
                wb.Save(path);

            }
        }

주: Aspose를 도입해야 합니다.dll 파일

좋은 웹페이지 즐겨찾기