Interop Excel - 如何设置excel文件总是在最后一行打开?

问题描述 投票:0回答:1

我每天都要在excel工作表中插入数据(使用Interop.Excel)。在插入数据后,用户会正常打开excel文件。我想要的是在打开excel文件时,在插入的最后一行或某一行滚动。这是我试过的,但没有效果。

if (position == mTables.Count - 1)
        {
            Microsoft.Office.Interop.Excel.Range activeCell = excelWorksheet.Cells[decalajMesaje, 1];
            activeCell.Select();
            activeCell.Activate();

            excelWorkbook.Worksheets[1].Cells[decalajMesaje, 1].Select();
            excelWorkbook.Worksheets[1].Cells[decalajMesaje, 1].Activate();

            excelWorkbook.Save();
        }

请问正确的方法是什么?

c#-4.0 excel-interop
1个回答
0
投票

你可以在C#中使用这个公式来查找工作表中使用的最后一行。

int lastUsedRow = excelWorkbook.Worksheets[1].Cells.Find("*", System.Reflection.Missing.Value,
                     System.Reflection.Missing.Value, System.Reflection.Missing.Value,
                     XlSearchOrder.xlByRows, XlSearchDirection.xlPrevious,
                     false, System.Reflection.Missing.Value, System.Reflection.Missing.Value).Row;
© www.soinside.com 2019 - 2024. All rights reserved.