回复 3楼xiwu的帖子
xiwu 你好,
测试代码如下:
- private void Form1_Load(object sender, EventArgs e)
- {
- this.fpSpread1.Sheets[0].ColumnHeader.Cells[0, 0].Text = "导出测试";
- this.fpSpread1.Sheets[0].ColumnHeader.Cells[0, 1].Text = "导出测试";
- this.fpSpread1.Sheets[0].ColumnHeader.Cells[0, 2].Text = "导出测试";
- this.fpSpread1.Sheets[0].ColumnHeader.Cells[0, 3].Text = "导出测试";
- this.fpSpread1.Sheets[0].Cells[0, 0].Text = "文本";
- this.fpSpread1.Sheets[0].Cells[0, 1].Text = "文本";
- this.fpSpread1.Sheets[0].Cells[0, 2].Text = "文本";
- this.fpSpread1.Sheets[0].Cells[0, 3].Text = "文本";
- }
- private void 导出ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.fpSpread1.SaveExcel("test.xls", FarPoint.Excel.ExcelSaveFlags.SaveBothCustomRowAndColumnHeaders);
- }
- private void 导入ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.fpSpread1.OpenExcel("test.xls");
- int colcount = this.fpSpread1.Sheets[0].GetLastNonEmptyColumn(FarPoint.Win.Spread.NonEmptyItemFlag.Data);
- for (int i = 0; i < colcount; i++)
- {
- this.fpSpread1.Sheets[0].ColumnHeader.Cells[0, i + 1].Text = this.fpSpread1.Sheets[0].Cells[0, i + 1].Text;
- }
- this.fpSpread1.Sheets[0].RemoveColumns(0, 1);
- this.fpSpread1.Sheets[0].RemoveRows(0, 1);
- }
复制代码 |