Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用c在一个单元格中使用多种格式#_C#_Excel - Fatal编程技术网

C# 使用c在一个单元格中使用多种格式#

C# 使用c在一个单元格中使用多种格式#,c#,excel,C#,Excel,我希望工作簿中的一个单元格中有多种格式类型。例如,我希望我的A1单元格显示“名称:Aaron Kruger”。当我以编程方式将名称“Aaron Kruger”添加到模板中时,它会自动将其加粗。所以它看起来像这样“名字:亚伦·克鲁格”。所以我想在同一个单元格中同时显示粗体和非粗体。也许将来我希望在同一个单元格中有两个不同大小的文本。 谢谢 亚伦·克鲁格 以下是我创建的函数: 以下是我传入的参数: 我录制了一个宏,把它翻译成C应该不难: 使用它可以将每个字符作为类型。现在使用它的字体和其他属性来设置

我希望工作簿中的一个单元格中有多种格式类型。例如,我希望我的A1单元格显示“名称:Aaron Kruger”。当我以编程方式将名称“Aaron Kruger”添加到模板中时,它会自动将其加粗。所以它看起来像这样“名字:亚伦·克鲁格”。所以我想在同一个单元格中同时显示粗体和非粗体。也许将来我希望在同一个单元格中有两个不同大小的文本。 谢谢 亚伦·克鲁格

以下是我创建的函数:

以下是我传入的参数:


我录制了一个宏,把它翻译成C应该不难:

使用它可以将每个字符作为类型。现在使用它的字体和其他属性来设置样式

请参考以下示例:

Microsoft.Office.Interop.Excel.Range=(Microsoft.Office.Interop.Excel.Range)单元格;
int TextLength=Range.Text.ToString().Length;

对于(int CharCount=1;CharCount请发布有问题的代码。public void inputData(int row,int column,string cellName,System.Windows.Forms.TextBox TextBox,Excel.sheet){sheet.Cells[row,column]=sheet.get_Range(cellName,Type.Missing)。Text+“”+TextBox.Text;//向工作表添加值}抱歉,我不知道如何在这里发布代码,使其看起来像在VS中一样。在我的模板中,单元格当前以粗体显示“Name:”。然后,当我添加名称“Aaron Kruger”时,它会像我预期的那样添加该名称。但它使名称成为“Aaron Kruger”也要加粗。我希望它添加名称,但不加粗。应该有一种方法可以在同一单元格中使用不同类型的字符串格式。顺便说一句,是的,这是为excel编码。这是我为我的工作而做的项目。我使用Microsoft.Office、Interop.excel和12.0
    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
    }
        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);
ActiveCell.FormulaR1C1 = "Test test"
Range("A1").Select
ActiveCell.FormulaR1C1 = "Test test"
With ActiveCell.Characters(Start:=1, Length:=5).Font
    .Name = "Calibri"
    .FontStyle = "Regular"
    .Size = 11
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = xlUnderlineStyleNone
    .ThemeColor = xlThemeColorLight1
    .TintAndShade = 0
    .ThemeFont = xlThemeFontMinor
End With
With ActiveCell.Characters(Start:=6, Length:=4).Font
    .Name = "Calibri"
    .FontStyle = "Bold"
    .Size = 11
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = xlUnderlineStyleNone
    .ThemeColor = xlThemeColorLight1
    .TintAndShade = 0
    .ThemeFont = xlThemeFontMinor
End With
 Microsoft.Office.Interop.Excel.Range Range = (Microsoft.Office.Interop.Excel.Range)Cell;
   int TextLength = Range.Text.ToString().Length;
   for (int CharCount = 1; CharCount <= TextLength; CharCount++)
   {
       Microsoft.Office.Interop.Excel.Characters charToTest = Range.get_Characters(CharCount, 1);
       bool IsBold = (bool)charToTest.Font.Bold;
       bool IsItalic = (bool)charToTest.Font.Italic;
       // other formatting tests here

   }
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
    }
}
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);