aspose.cell 제작 excel 흔한 쓰기

10078 단어 Excel
// Excel 

                Workbook workbook = new Workbook();

                Worksheet worksheet = workbook.Worksheets[0];

                Style styleHeader = workbook.Styles[workbook.Styles.Add()];

                styleHeader.Font.Size = 12;

                styleHeader.HorizontalAlignment = TextAlignmentType.Center;

                Style stylePowerInfo = workbook.Styles[workbook.Styles.Add()];

                stylePowerInfo.IsTextWrapped = true;

                Style styleTextCenter = workbook.Styles[workbook.Styles.Add()];

                styleTextCenter.HorizontalAlignment = TextAlignmentType.Center;

                Style styleTitle = workbook.Styles[workbook.Styles.Add()];

                styleTitle.Font.IsBold = true;

                styleTitle.Font.Size = 16;

                styleTitle.HorizontalAlignment = TextAlignmentType.Center;

                styleTitle.ForegroundColor = Color.LightGreen;

                // 

                worksheet.Cells[0, 0].Value = " ";

                worksheet.Cells.Merge(0, 0, 1, 2);

                worksheet.Cells[0, 0].SetStyle(styleTitle);

                worksheet.Cells[1, 0].Value = " ";

                worksheet.Cells[1, 0].SetStyle(styleTitle);

                worksheet.Cells[1, 1].Value = " ";

                worksheet.Cells[1, 1].SetStyle(styleTitle);
//i+2 

                for (int i = 0; i < Convert.ToInt32(param[0]); i++)

                {

                    try

                    {

                        if (this.InvokeRequired)

                        {



                            worksheet.Cells[i + 2, 0].PutValue(GetListText(i, 2));

                            worksheet.Cells[i + 2, 0].SetStyle(styleTextCenter);

                            worksheet.Cells[i + 2, 1].PutValue(GetListText(i, 3));

                            worksheet.Cells[i + 2, 1].SetStyle(styleTextCenter);

                        }

                        else

                        {

                            worksheet.Cells[i + 2, 0].PutValue(this.listView.Items[i].SubItems[2].Text);

                            worksheet.Cells[i + 2, 0].SetStyle(styleTextCenter);

                            worksheet.Cells[i + 2, 1].PutValue(this.listView.Items[i].SubItems[3].Text);

                            worksheet.Cells[i + 2, 1].SetStyle(styleTextCenter);

                        }

                        if (progressBarX1.InvokeRequired)

                        {

                            progressBarX1.Invoke(new Action<int>(s => { this.progressBarX1.Value = s; }), i);

                        }

                        else

                        {

                            this.progressBarX1.Value = i;

                        }

                        if (lbState.InvokeRequired)

                        {

                            lbState.Invoke(new Action<string>(s => { this.lbState.Text = s; }), " " + i + " / " + (this.listView.Items.Count - 1).ToString() + " , ...");

                        

                        }

                        else

                        {

                            this.lbState.Text = " " + i + " / " + (this.listView.Items.Count - 1).ToString() + " , ...";

                        }



                    }

                    catch (Exception ex)

                    {

                        isSuccessful = false;

                        WriteLog(ex, " ", false);

                        continue;

                    }

                }

                // 

                worksheet.Cells.SetColumnWidthPixel(0, 150);

                worksheet.Cells.SetColumnWidthPixel(1, 150);

                workbook.Save(FileFullName);
 // 

worksheet.Cells.Merge(rowIndex - userRowSpan, 0, userRowSpan, 1);

이상은listview에서 excel로 데이터를 내보내는 것을 예로 들었습니다

좋은 웹페이지 즐겨찾기