代码:C#
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook xlBook;
Microsoft.Office.Interop.Excel.Worksheet xlSheet;
int rowIndex = 1;
int colIndex = 0;
xlBook = xlApp.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlBook.Sheets["sheet1"];
xlSheet.Name = dateTimePicker1.Value.ToShortDateString() + "生产部日考勤";
for (int i = 0; i <= dataGridView1.Columns.Count - 1; i++)
{
colIndex = colIndex + 1;
xlApp.Cells[1, colIndex] = dataGridView1.Columns[i].HeaderText;
}
for (int row = 0; row <= dataGridView1.Rows.Count - 1; row++)
{
rowIndex = rowIndex + 1;
colIndex = 0;
for (int col = 0; col <= dataGridView1.Columns.Count - 1; col++)
{
colIndex = colIndex + 1;
xlApp.Cells[rowIndex, colIndex] = dataGridView1.Rows[row].Cells[col].Value;
}
}
xlApp.Visible = true;
}
报错:未处理的“System.Runtime.InteropServices.COMException”类型的异常出现在 ProductionSalarySystem.dll 中。其他信息: 在重命名工作表或图表时输入的名称无效。请尝试以下操作: • 确认输入的名称不多于 31 个字符。
• 确认名称中不包含下列任一字符: : / ? * [ 或 ] 。
• 确认工作表名称不为空。
但是我改了名称多次,甚至是改为数字都会报同样的错误。我名称没有空格,没有为空,没有多余的字符,没有特殊的字符。但就是会报这样的错误。希望大家帮帮忙啊
不甚感谢大家
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook xlBook;
Microsoft.Office.Interop.Excel.Worksheet xlSheet;
int rowIndex = 1;
int colIndex = 0;
xlBook = xlApp.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlBook.Sheets["sheet1"];
xlSheet.Name = dateTimePicker1.Value.ToShortDateString() + "生产部日考勤";
for (int i = 0; i <= dataGridView1.Columns.Count - 1; i++)
{
colIndex = colIndex + 1;
xlApp.Cells[1, colIndex] = dataGridView1.Columns[i].HeaderText;
}
for (int row = 0; row <= dataGridView1.Rows.Count - 1; row++)
{
rowIndex = rowIndex + 1;
colIndex = 0;
for (int col = 0; col <= dataGridView1.Columns.Count - 1; col++)
{
colIndex = colIndex + 1;
xlApp.Cells[rowIndex, colIndex] = dataGridView1.Rows[row].Cells[col].Value;
}
}
xlApp.Visible = true;
}
报错:未处理的“System.Runtime.InteropServices.COMException”类型的异常出现在 ProductionSalarySystem.dll 中。其他信息: 在重命名工作表或图表时输入的名称无效。请尝试以下操作: • 确认输入的名称不多于 31 个字符。
• 确认名称中不包含下列任一字符: : / ? * [ 或 ] 。
• 确认工作表名称不为空。
但是我改了名称多次,甚至是改为数字都会报同样的错误。我名称没有空格,没有为空,没有多余的字符,没有特殊的字符。但就是会报这样的错误。希望大家帮帮忙啊
不甚感谢大家
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货