代码没有问题,只是你Excel中看上去是只有两个Sheet,其实有4个Sheet,其中Sheet1和Sheet2都被隐藏了
png
- private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- try
- {
- fpSpread1.OpenExcel(Application.StartupPath + @"\Template\账簿套打模板\账簿模板.xls");
- foreach (SheetView view in fpSpread1.Sheets)
- {
- view.Visible = true;
- }
- }
- catch
- {
- }
- //Int32 curRow = 4;
- //int nYear, nMonth, nDay;
- int SelIndex = 2;//cbmBookType.SelectedIndex;
- SheetView st = fpSpread1.Sheets[SelIndex];
- //临时行列
- int iTmpRow = -1;
- int iTmpCol = -1;
- iTmpRow = 1;
- while (iTmpRow >= 0)
- {
- fpSpread1.Search(SelIndex, "?企业名称", false, false, true, false, 0, 0, ref iTmpRow, ref iTmpCol);
- if (iTmpRow != -1)
- st.Cells[iTmpRow, iTmpCol].Value = st.Cells[iTmpRow, iTmpCol].Value.ToString().Replace("?企业名称", "我的企业名称");
- else
- break;
- }
- }
复制代码 |