使用c#在一个单元格中使用多个格式 [英] Multiple Formats in one cell using c#
本文介绍了使用c#在一个单元格中使用多个格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谢谢,
Aaron Kruger
这是我创建的功能:
public void inputData(int row,int column,string cellName,System.Windows.Forms.TextBox textBox,Excel.Worksheet sheet)
{
sheet.Cells [row,column] = sheet.get_Range(cellName,Type.Missing).Text ++ textBox.Text; //为价值
$ b $ / code $ <$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ : inputData(5,1,A5,tbTagNumber,xlSheet);
inputData(6,1,A6,tbCustomer,xlSheet);
inputData(7,1,A5,tbDataFile,xlSheet);
inputData(3,6,F3,tbJobNumber,xlSheet);
inputData(4,6,F4,tbMeterSN,xlSheet);
inputData(6,6,F6,tbPO,xlSheet);
inputData(7,6,F7,tbFlowplate,xlSheet);
inputData(4,9,I4,tbElectronicSN,xlSheet);
解决方案
范围rng1 = ws.getRange(A1,E10); (int i = 0; i< 10; i ++)
{
范围rngTst = rng.cells [i,i];
for(int j = 0; j< rngTst.get_characters()。count; j ++)
{
rngTst.application.activecell.get_characters(j,j).font.color
}
}
或
int sFirstFoundAddress = currentFind.FormulaR1C1Local.ToString()。IndexOf(NOT FOR CIRCULATION);
get_Range(excel.Cells [1,1],
excel.Cells [1,dtData.Columns.Count])
.get_Characters(sFirstFoundAddress,20)。 Color =
System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
I want to have mutple format types in one cell in my workbook. For example I want my A1 cell to display " Name: Aaron Kruger ". When I programmatically add the name "Aaron Kruger" to the template, it automatically makes it bold. So instead it looks like this " Name:Aaron Kruger ". So I want Bold and non-bold both in the same cell. And maybe in the future I will want two different text sizes in the same cell.
Thanks,
Aaron Kruger
Here is the function I created:
public void inputData(int row, int column, string cellName, System.Windows.Forms.TextBox textBox, Excel.Worksheet sheet)
{
sheet.Cells[row, column] = sheet.get_Range(cellName, Type.Missing).Text + " " + textBox.Text; // adds value to sheet
}
Here are the arguments I pass in:
inputData(5, 1, "A5", tbTagNumber, xlSheet);
inputData(6, 1, "A6", tbCustomer, xlSheet);
inputData(7, 1, "A5", tbDataFile, xlSheet);
inputData(3, 6, "F3", tbJobNumber, xlSheet);
inputData(4, 6, "F4", tbMeterSN, xlSheet);
inputData(6, 6, "F6", tbPO, xlSheet);
inputData(7, 6, "F7", tbFlowplate, xlSheet);
inputData(4, 9, "I4", tbElectronicSN, xlSheet);
解决方案 Range rng1 = ws.getRange("A1","E10");
for(int i=0;i<10;i++)
{
Range rngTst=rng.cells[i,i];
for(int j=0;j<rngTst.get_characters().count;j++)
{
rngTst.application.activecell.get_characters(j,j).font.color
}
}
or
int sFirstFoundAddress = currentFind.FormulaR1C1Local.ToString().IndexOf("NOT FOR CIRCULATION ");
get_Range(excel.Cells[1, 1],
excel.Cells[1, dtData.Columns.Count])
.get_Characters(sFirstFoundAddress, 20).Font.Color =
System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
这篇关于使用c#在一个单元格中使用多个格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文