c#更新Excel中的数据链接
Code
using Microsoft.Office.Interop.Excel;
private bool RefreshExcelData(string strFileName){
object missing = System.Reflection.Missing.Value;
ApplicationClass readApp = new ApplicationClass();
Workbook readBook = null;
try{
readBook = readApp.Workbooks.Open(strFileName, 3, false, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Array links = (Array)readBook.LinkSources(XlLink.xlExcelLinks);
if (links != null)
{
//递归更新源Excel
foreach (string strName in links)
RefreshExcelData(strName);
//更新当前Excel
foreach (string strName in links)
readBook.UpdateLink(strName, XlLinkType.xlLinkTypeExcelLinks);
//刷新计算
readBook.RefreshAll();
readBook.Save();
}
}
catch(){}
}
using Microsoft.Office.Interop.Excel;
private bool RefreshExcelData(string strFileName){
object missing = System.Reflection.Missing.Value;
ApplicationClass readApp = new ApplicationClass();
Workbook readBook = null;
try{
readBook = readApp.Workbooks.Open(strFileName, 3, false, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Array links = (Array)readBook.LinkSources(XlLink.xlExcelLinks);
if (links != null)
{
//递归更新源Excel
foreach (string strName in links)
RefreshExcelData(strName);
//更新当前Excel
foreach (string strName in links)
readBook.UpdateLink(strName, XlLinkType.xlLinkTypeExcelLinks);
//刷新计算
readBook.RefreshAll();
readBook.Save();
}
}
catch(){}
}
using Microsoft.Office.Interop.Excel;
private bool RefreshExcelData(string strFileName){
object missing = System.Reflection.Missing.Value;
ApplicationClass readApp = new ApplicationClass();
Workbook readBook = null;
try{
readBook = readApp.Workbooks.Open(strFileName, 3, false, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Array links = (Array)readBook.LinkSources(XlLink.xlExcelLinks
if (links != null)
{
//递归更新源Excel
foreach (string strName in links)
RefreshExcelData(strName);
//更新当前Excel
foreach (string strName in links)
readBook.UpdateLink(strName, XlLinkType.xlLinkTypeExcelLinks);
//刷新计算
readBook.RefreshAll();
readBook.Save();
}
}
catch(){}
} using Microsoft.Office.Interop.Excel;
private bool RefreshExcelData(string strFileName){
object missing = System.Reflection.Missing.Value;
ApplicationClass readApp = new ApplicationClass();
Workbook readBook = null;
try{
readBook = readApp.Workbooks.Open(strFileName, 3, false, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Array links = (Array)readBook.LinkSources(XlLink.xlExcelLinks
if (links != null)
{
//递归更新源Excel
foreach (string strName in links)
RefreshExcelData(strName);
//更新当前Excel
foreach (string strName in links)
readBook.UpdateLink(strName, XlLinkType.xlLinkTypeExcelLinks);
//刷新计算
readBook.RefreshAll();
readBook.Save();
}
}
catch(){}
}
using Microsoft.Office.Interop.Excel;
object missing = System.Reflection.Missing.Value;
ApplicationClass readApp = new ApplicationClass();
Workbook readBook = null;
try{
readBook = readApp.Workbooks.Open(strFileName, 3, false, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Array links = (Array)readBook.LinkSources(XlLink.xlExcelLinks
if (links != null)
{
//递归更新源Excel
foreach (string strName in links)
RefreshExcelData(strName);
//更新当前Excel
foreach (string strName in links)
readBook.UpdateLink(strName, XlLinkType.xlLinkTypeExcelLinks);
//刷新计算
readBook.RefreshAll();
readBook.Save();
}
}