2009/02/04(Wed) 18:10:52 編集(投稿者)
■No32313 (CL-orz'3 さん) に返信
> 「Error:RangeクラスのNumberFormatプロパティを設定できません。Line:Microsoft Office Excel」
それでは、NumberFormatLocal では如何でしょう。
using System;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;
public partial class Program
{
public static void Main(string[] args)
{
Excel.Application appExcel2007 = null;
Excel.Workbooks books = null;
Excel.Workbook book = null;
Excel.Sheets sheets = null;
Excel.Worksheet sheet = null;
Excel.Range rng = null;
Excel.Range rng2 = null;
try
{
appExcel2007 = new Excel.ApplicationClass();
books = appExcel2007.Workbooks;
book = books.Add(Type.Missing);
sheets = book.Worksheets;
sheet = (Excel.Worksheet)sheets[1];
appExcel2007.Visible = true;
rng = sheet.get_Range("A1:A3", Type.Missing);
rng.set_Value(Type.Missing, new object[,] { { 123456 }, { -123456 }, { 0 } });
//rng.NumberFormat = "[Blue][>0]#,0;[Red][<0]-0;[Black]0";
rng.NumberFormatLocal = "[青][>0]#,0;[赤][<0]-0;[黒]0";
book.Saved = true;
//appExcel2007.Quit();
}
finally
{
ReleaseObject(rng, sheet, sheets, book, books, rng2, appExcel2007);
}
}
public static void ReleaseObject(params object[] objects)
{
foreach (object o in objects)
{
try
{
if (o != null && Marshal.IsComObject(o))
{
Marshal.ReleaseComObject(o);
}
}
catch {}
}
}
}