如何发送Sharepoint列表项ID到Excel文件?

我有一个Sharepoint(2007)列表中的一些项目。 当我点击其中的一个项目时,会打开一个包含大量macros的Excel(2003)文件。 我需要获得这个(Sharepoint)项目的ID,并将其发送到我的Excel文件的单元格…然后macros将被执行,并获得我们需要这个ID的所有数据。

我怎样才能发送项目的ID到我的Excel文件?

任何想法 ? 谢谢

我曾经写了一个DataTable到一个新的Excel文件。 所以你可以继续前进,并将函数参数从DataTable更改为SPList / SPLisItem,并写入一个现有的文件(我当前的实现写入一个新的Excel文件,每次我执行此function)。 此外,请确保您为Excel(COM)对象添加引用,例如Microsoft Excel 12.0对象库等。如果您需要更多帮助,请告诉我。

public void excelgenerate(DataSet ds) { Microsoft.Office.Interop.Excel.Application oAppln; //declaring work book Microsoft.Office.Interop.Excel.Workbook oWorkBook; //declaring worksheet Microsoft.Office.Interop.Excel.Worksheet oWorkSheet; oAppln = new Microsoft.Office.Interop.Excel.Application(); oWorkBook = (Microsoft.Office.Interop.Excel.Workbook)(oAppln.Workbooks.Add(true)); Microsoft.Office.Interop.Excel.Range wRange; foreach (DataTable table in ds.Tables) { oWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)(oWorkBook.Worksheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing)); oWorkSheet.Name = table.TableName; oWorkSheet.Activate(); DataRow dr = table.Rows[0]; string path = dr["Path"].ToString(); if (path.Length > 0) { string[] mylist = path.Split('\\'); var features = Array.FindLastIndex(mylist, str => str.Equals("Features")); string stringmine = "Type ---> " + mylist[4] + "/" + mylist[5] + " Project Name ---> " + mylist[6] + " Feature Name ---> " + mylist[features + 1]; oWorkSheet.Cells[1, 1] = stringmine; Microsoft.Office.Interop.Excel.Range colrange = oWorkSheet.get_Range(oWorkSheet.Cells[1, 1], oWorkSheet.Cells[1, 8]); colrange.Merge(true); } int ColumnIndex = 0; foreach (DataColumn col in table.Columns) { ColumnIndex++; oWorkSheet.Cells[2, ColumnIndex] = col.ColumnName; wRange = (Microsoft.Office.Interop.Excel.Range)oWorkSheet.Cells[2, ColumnIndex]; wRange.Font.Bold = true; } int rowIndex = 1; foreach (DataRow row in table.Rows) { rowIndex++; ColumnIndex = 0; foreach (DataColumn col in table.Columns) { ColumnIndex++; oWorkSheet.Cells[rowIndex + 1, ColumnIndex] = row[col.ColumnName].ToString(); } } oWorkSheet.Columns.AutoFit(); oWorkSheet.Rows.AutoFit(); } string fileName = System.Guid.NewGuid().ToString().Replace("-", "") + ".xls"; Console.WriteLine("Number of sheets written : " + oWorkBook.Worksheets.Count); oWorkBook.SaveAs(fileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, null, null, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null); oWorkBook.Close(null, null, null); oAppln.Quit(); } 

对于使用C#ASP.NET和SharePoint执行macros,我build议你使用这篇文章

希望它能回答你的问题!

除非有什么理由不能直接将SharePoint列表数据链接到工作表中,并将macros带入电子表格中,否则我认为以下步骤将为您提供所需的内容。 这似乎太简单了…一定有一个原因,这不适合你想要做的。 无论如何,下面是使这项工作的步骤:

1)确保SharePoint列表实际上有一个强制唯一值的索引列。 您可以通过查看文档库设置来检查这一点。 看看确保有列列表下的索引列。 如果没有,您可以通过select“创build新列”操作创build一个,select您的数据types,并确保您select“强制唯一值”的单选button。

2)使用库的主页面菜单中的“export to excel”选项将库导出为ex​​cel。 这将默认build立一个数据链接,并将excel查询文件存储在您的机器的默认位置,您可以通过转到数据选项卡并select“连接”来发现它。

3)将macros复制到链接到数据源的电子表格中,并调整macros中的引用以从SharePoint列表中提取所需的信息。

希望这可以帮助。