Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 751987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:43:47+00:00 2026-05-14T14:43:47+00:00

static void Main() { Application excelapp = new Application(); Workbook book = excelapp.Workbooks.Open(@C:\HWYFAB.xlsx, 0,

  • 0
static void Main()
{
  Application excelapp = new Application();
  Workbook book = excelapp.Workbooks.Open(@"C:\HWYFAB.xlsx",
    0, false, 5, "", "", false, XlPlatform.xlWindows , "",
    true, false, 0, true, false, false);

  Worksheet sheet = (Worksheet)book.Sheets[1];

  Range cell = (Range)sheet.Cells[3, 2];
  Console.WriteLine(cell.Text);
  cell.ClearContents();
  book.Close(true, "HWYFAB.xlsx", false);
  excelapp.Quit();
}

This program runs and exits as expected. It does print the correct value that’s in cell B3 to the console. When closing it asks if I want to replace the existing file. I click yes. When I open the spreadsheet in Excel, the value is still in cell B3 despite the cell.ClearContents().

Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:43:47+00:00Added an answer on May 14, 2026 at 2:43 pm

    Your call to cell.ClearContents() will clear formulas and value constants from the cell. This should absolutely be working. You can confirm this after your call to cell.ClearContents() by testing if cell.Value2 == null, which should be true.

    I believe that the problem with your code is in the call to book.Close(true, "HWYFAB.xlsx", false). The problem is that you are explicitly passing in the name of your workbook, but you are leaving off the path. (Note that when you open the workbook you are including the full path, including the “C:\” directory.) By leaving off the full path to the workbook when you save, you are saving to the current directory, which could be “My Documents” or anywhere else.

    If you wish to save the workbook in-place, at its original location, then you should pass in Type.Missing for the Filename parameter. For example:

    book.Close(true, Type.Missing, false);
    

    This idea is untested, but I’m fairly confident that this should work for you. Give it a try…

    — Mike

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public static void main(String[] args) { List<? extends Object> mylist = new ArrayList<Object>(); mylist.add(Java);
public class Test { public static void main(String[] args) { } } class Outer
public class doublePrecision { public static void main(String[] args) { double total = 0;
public class WrapperTest { public static void main(String[] args) { Integer i = 100;
This code compiles: private static void Main(string[] args) { bool? fred = true; if
class Program { static void Main(string[] args) { String value = Two; Type enumType
Here is a quick test program: public static void main( String[] args ) {
The following code public class GenericsTest2 { public static void main(String[] args) throws Exception
Take the following useless program: class Program { static void Main(string[] args) { IUnityContainer
The method signature of a Java main method is: public static void main(String[] args)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.