通过拷贝模板Excel文件,然后添加数据,形成本地Excel报表。现在到最后一步难住了:有立方米的单元格,要把M后面的数字3变为上标,找了两周也没找到实现的办法。程序主要代码如下:using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Tools.Excel; //产生一个Excel.Application的新进程
Excel.Application excel = new Excel.Application();
……
Excel.Workbooks workbooks = excel.Workbooks; Excel.Sheets sheets = wb.Worksheets;
……
int sCount = sheets.Count;
Excel.Worksheet[] ws = new Excel.Worksheet[sCount];在Excel中操作录制宏得到VBA代码中得到SuperScript属性,在MSDN中查询到Characters有此属性,应该是在Microsoft.Office.Tools.Excel名称空间中,但是具体的使用中没调试成功。这是MSDN中查询到的代码,放在我的导出方法中,第二行就报错。不知道如何在NamedRange中设定选定的单元格。 Microsoft.Office.Tools.Excel.NamedRange charactersRange; charactersRange = this.Controls.AddNamedRange(Range["A1", "A1"], "charactersRange");
charactersRange.Value2 = "Smith";
charactersRange.Characters[1, 1].Font.Bold = true;
charactersRange.Characters[1, 1].Font.Size = 14;
charactersRange.Characters[1, 1].Font.Superscript = true;或者是有其他代码控制Excel实现目标的方法吗?
请高手给予请教,万分感谢!
using Microsoft.Office.Tools.Excel; //产生一个Excel.Application的新进程
Excel.Application excel = new Excel.Application();
……
Excel.Workbooks workbooks = excel.Workbooks; Excel.Sheets sheets = wb.Worksheets;
……
int sCount = sheets.Count;
Excel.Worksheet[] ws = new Excel.Worksheet[sCount];在Excel中操作录制宏得到VBA代码中得到SuperScript属性,在MSDN中查询到Characters有此属性,应该是在Microsoft.Office.Tools.Excel名称空间中,但是具体的使用中没调试成功。这是MSDN中查询到的代码,放在我的导出方法中,第二行就报错。不知道如何在NamedRange中设定选定的单元格。 Microsoft.Office.Tools.Excel.NamedRange charactersRange; charactersRange = this.Controls.AddNamedRange(Range["A1", "A1"], "charactersRange");
charactersRange.Value2 = "Smith";
charactersRange.Characters[1, 1].Font.Bold = true;
charactersRange.Characters[1, 1].Font.Size = 14;
charactersRange.Characters[1, 1].Font.Superscript = true;或者是有其他代码控制Excel实现目标的方法吗?
请高手给予请教,万分感谢!
Excel.Workbook workbookData;
Excel.Worksheet worksheetData; // set culture to US
System.Globalization.CultureInfo CurrentCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); workbookData = appExcel.Workbooks.Add(Missing.Value);
// workbookData.Worksheets.Delete();
worksheetData = (Excel.Worksheet)workbookData.Worksheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);
worksheetData.Name = "Saved"; worksheetData.Cells[2, 2] = "1M³"; // return to previous culture
System.Threading.Thread.CurrentThread.CurrentCulture = CurrentCI; workbookData.Saved = false;
workbookData.SaveAs(filedialog.FileName,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Excel.XlSaveAsAccessMode.xlNoChange,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value); appExcel.Quit();立方米的符号 “Alt+179”,平方米“ Alt+178”
http://www.cnblogs.com/sunrack/articles/804241.html