如何往EXCEL里面的批注写入值

Lixin19821010 2007-12-13 12:57:25
<?xml version="1.0"?>
<head>
<title>主要原料成本预算表</title>
<meta name="autofit" row="false" column="true"/>
<script language="python">
rows=[
('BC=','乙烯', 0, 0),
('NA1','石脑油', 0, 0),
('LHC','轻烃', 0, 0),
('AAE','丙烯酸甲酯', 0, 0),
('MAM','甲基丙烯磺酸钠', 0, 0),
('BMI','原料煤', 0, 0)
]
</script>
<script language="python" src="/scripts/buy_main.py" />
</head>
如上所表示.这些值都是EXCEL单元格A1内的.
假如我现在把 ROWS 里面的值全都读了出来,并且也做了修改,得到了修改之后的数据:
('BZN','纯苯', 1, 1),
('MC7','甲苯', 1, 1),
('OXA','邻二甲苯', 1, 1),
('BPX','对二甲苯', 1, 1),
('XYL','混二甲苯', 1, 1),
我的问题是:如何保存修改之后的数据
是否利用利用EXCEL AUTOMATION?(我对这个概念很不清晰).
十分感谢关注 :)
...全文
164 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lixin19821010 2007-12-14
  • 打赏
  • 举报
回复
...
lm4242 2007-12-14
  • 打赏
  • 举报
回复
Excel.Application app = null;
Excel.Workbook wb = null;
Excel.Worksheet ws = null;
Excel.Range rng = null;

try
{
app = new Excel.Application(); // 创建application对象
app.Visible = false;
app.ScreenUpdating = false;

// 打开文件
wb = app.Workbooks.Open(@"D:\test.xls", Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing);

ws = (Excel.Worksheet)wb.Sheets[1];// 指定worksheet

rng = ws.get_Range("A1", Missing.Value);// 获取单元格
// 如果有批注则删除
if (rng.Comment != null)
{
object obj = rng.Comment;
rng.Comment.Delete();
}
rng.AddComment("comment changed" + DateTime.Now);
wb.Save(); // 保存
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
wb.Close(true, Type.Missing, Type.Missing);
app.Quit();
wb = null;
app = null;
GC.Collect();
}
Lixin19821010 2007-12-14
  • 打赏
  • 举报
回复
Excel.Application xApp = new Excel.ApplicationClass();
xApp.Application.Workbooks.Add(true);
xApp.Visible = false;
Excel.Workbook xBook = xApp.Workbooks.Open(@"D:\CData",
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);
xBook = xApp.Workbooks.Add(Missing.Value);
#region 1
Excel.Worksheet xSheet = (Excel.Worksheet)xBook.Sheets[1];
//Excel.Worksheet xSheet = (Excel.Worksheet)xApp.ActiveSheet;
Excel.Range rng1 = xSheet.get_Range("A1", Missing.Value);

Excel.Comment excelComment1 = rng1.Comment;
//if (rng1.Comment != null)
//{
// object iii = rng1.Comment;
// rng1.Comment.Delete();
//}
rng1.AddComment("Comment Added \n" + System.DateTime.Now.ToString());
rng1.Value = "Comment Added";
object iiii = rng1.Comment;
Lixin19821010 2007-12-13
  • 打赏
  • 举报
回复
求助中......
Lixin19821010 2007-12-13
  • 打赏
  • 举报
回复
:)
等待中............
Lixin19821010 2007-12-13
  • 打赏
  • 举报
回复
upup :)
着急啊.

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧