简体   繁体   中英

C#, Microsoft interop, Excel numberformat problem

I am using C# to try and format a range in Excel as numbers. When doing this, I get the green error arrow in the corner to ask me if I want to format the column as a number.

I used the code below to format the data:

Excel.Range Data = currentSheet.get_Range("K2:K10", Type.Missing);
Data.NumberFormat = "0.00";

How do I convert the range to numbers so that excel is happy?

If your cells are already formatted as numbers, using the PasteSpecial function might work:

Excel.Range Data = currentSheet.get_Range("K2:K10", Type.Missing);
Data.Copy(System.Type.Missing);
Data.PasteSpecial(XlPasteType.xlPasteAll, XlPasteSpecialOperation.xlPasteSpecialOperationAdd,
        false, false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM