c# - 如何在不使用 C# 覆盖的情况下附加到现有 Excel 文件?
问题描述
private void newsubmit_Click(object sender, EventArgs e)
{
int y;
string[] range;
range = new string[999];
if ( newid.Text != null)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(@"C:\Users\Administrator\Desktop\coach ceazar\CLIENTS", 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
object misValue = System.Reflection.Missing.Value;
for (y = 1; y < xlWorkSheet.UsedRange.Columns.Count; y++)
{
xlWorkSheet.Cells[y][newid.Text].copy();
range[y] = Clipboard.GetText();
}
xlApp.UserControl = false;
xlWorkBook.Close(false);
xlWorkBook = xlApp.Workbooks.Open(@"C:\Users\Administrator\Desktop\coach ceazar\classes\" + classes[classnumber-1].Text+".xls", 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
for (int w = 1; w < y; w++)
{
xlWorkSheet.Cells[w][xlWorkSheet.UsedRange.Rows.Count+1]=range[w];
}
xlApp.UserControl = false;
xlWorkBook.Save();
xlApp.Visible = true;
}
else MessageBox.Show("please enter the id to be enrolled!");
}
我正在尝试使用 C# 将一整行从一个 Excel 文件复制到另一个文件。这是我当前的代码,但每次代码运行时,它都会覆盖 Excel 文件中已有的内容。这真的让我很沮丧 - 有人可以帮忙吗?
解决方案
推荐阅读
- c# - 集合父记录中循环的性能
- html - 如何强制 html 表格的“td”元素中的单独元素显示内联(从左到右)?
- regex - sed 将不匹配下一行
- azure - Azure 搜索如何存储索引数据
- c - “有条件的跳转或移动取决于未初始化的值”,同时释放一个 char **
- machine-learning - 无法使用通用近似定理拟合曲线 (x**3.4 + x**0.7)
- python - 如何在python中计算字符串中的单词
- xml - 从列中选择 XML 数据,除了某些值 T-SQL
- php - php,按日期升序对文件进行排序,标记为红色文本
- linux - /usr/bin/bash: 没有这样的文件或目录