Exemplo n.º 1
0
        /// <summary>
        /// Get last used column for a specific row
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            ExcelUsed eu = new ExcelUsed();

            try
            {
                int results = eu.LastColumnForRow(fileName, sheetName, 2);
                // send results to Visual Studio Output window
                Console.WriteLine(results);
            }
            finally
            {
                eu.CallGarbageCollector();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get last used column for a specific row
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// If you call the code below minus the finally Excel stays
        /// in memory but will be released when the app closes
        ///
        /// When running this demo, open Task Manager.
        /// Try running code with the CheckBox checked then un-checked
        ///  - When checked, we make a call to the garbage collector which
        ///    will release memory but is not prudent. Only time this method
        ///    should be used is when an operation such as this one is called
        ///    many times and might cause the system to run low or out of memory
        ///  - When un-checked memory is released when the app is closed.
        /// </remarks>
        private void button2_Click(object sender, EventArgs e)
        {
            int       row = (int)numericUpDown1.Value;
            ExcelUsed eu  = new ExcelUsed();

            try
            {
                int results = eu.LastColumnForRow(fileName, sheetName, row);
                MessageBox.Show($"Row {row}: {results}");
            }
            finally
            {
                if (forceCheckBox.Checked)
                {
                    eu.CallGarbageCollector();
                }
            }
        }