【发布时间】:2017-12-13 12:27:44
【问题描述】:
我需要使用 c# 语言为自动颜色的 Excel 单元格添加边框。下面给出的是我使用的编码。但它不会为单元格添加任何边框。你能告诉我我在这里做错了什么吗:
当我尝试为单元格指定边框样式时,我没有获得任何边框设计功能:
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlApp.Visible = false;
xlWorkBook = xlApp.Workbooks.Open(textBox1.Text, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int i = 0;
int j = 0;
for (i = 0; i <= dataGridView1.RowCount - 1; i++)
{
for (j = 0; j <= dataGridView1.ColumnCount - 1; j++)
{
DataGridViewCell cell = dataGridView1[j, i];
xlWorkSheet.Cells["19", "I"] = "Availablility";
xlWorkSheet.Cells[i + 20, j + 9] = cell.Value;
xlWorkSheet.Cells.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlMedium, Excel.XlColorIndex.xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic);
}
}
【问题讨论】:
-
我不确定您的颜色属性是否正常。如果删除最后一个参数,它会起作用吗?此外,该文档说“您必须指定 ColorIndex 或 Color,但不能同时指定两者。您可以指定 LineStyle 或 Weight,但不能同时指定两者。如果您不指定任何一个参数,Microsoft Excel 将使用默认的线条样式和粗细”
-
@John 如果我删除任何参数,它会抛出一个名为“方法“BorderAround”没有重载需要“3”个参数”的错误。我想我需要包括所有四个参数,因为如果我删除所有它会抛出一个错误,称为“方法“BorderAround”没有重载需要'0'参数”