.NET 4.0的F#和Excel集成(Visual Studio 2010 Beta 1)

编程入门 行业动态 更新时间:2024-10-24 14:16:28
本文介绍了.NET 4.0的F#和Excel集成(Visual Studio 2010 Beta 1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

任何人都可以在这里使用Web链接或演示如何使用.NET 4.0(Visual Studio 2010 Beta 1)进行F#和Excel集成?

Can anyone give a web link to or demonstrate here how to do F# and Excel integration using .NET 4.0 (Visual Studio 2010 Beta 1)?

我知道如何在CTP发行版中这样做,但据我所知,.NET 4.0(Visual Studio 2010 Beta 1)应该更简单。

I know how to do this in the CTP release but as far as I know it should be simpler in .NET 4.0 (Visual Studio 2010 Beta 1).

推荐答案

在最新的F#CTP版本(Visual Studio 2010 Beta1)中添加了secret sauce,以改善Office interop。也许你有F#与 C#对Dynamic的新支持。

There is no 'secret sauce' added to the latest F# CTP release (Visual Studio 2010 Beta1) to improve Office interop. Perhaps you have F# confused with C#'s new support for Dynamic.

但是,F#中的Office interop与C#相同 - 您可以使用本机COM API或更新的受管理的Visual Studio Tools for Office(VSTO)库。不幸的是,F#没有用于创建C#的VSTO加载项的UI设计器,所以做最简单的办法是使用COM API。

However, Office interop in F# is the same as C# - you can use the native COM APIs or the newer, managed Visual Studio Tools for Office (VSTO) libraries. Unfortunately F# doesn't have the UI-designers for creating VSTO add-ins like C#, so the simplest way to do Office interop is to use the COM APIs.

以下代码片段创建一个包含我的图片文件夹中图片信息的Excel工作表:

The following snippet creates an Excel worksheet with information about the pictures in your My Pictures folder:

#r "Microsoft.Office.Interop.Excel" open System open System.IO open System.Reflection open Microsoft.Office.Interop.Excel let app = ApplicationClass(Visible = true) let sheet = app.Workbooks .Add() .Worksheets.[1] :?> _Worksheet let setCellText (x : int) (y : int) (text : string) = let range = sprintf "%c%d" (char (x + int 'A')) (y+1) sheet.Range(range).Value(Missing.Value) <- text let printCsvToExcel rowIdx (csvText : string) = csvText.Split([| ',' |]) |> Array.iteri (fun partIdx partText -> setCellText partIdx rowIdx partText) let rec filesUnderFolder basePath = seq { yield! Directory.GetFiles(basePath) for subFolder in Directory.GetDirectories(basePath) do yield! filesUnderFolder subFolder } // Print header printCsvToExcel 0 "Directory, Filename, Size, Creation Time" // Print rows filesUnderFolder (Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)) |> Seq.map (fun filename -> new FileInfo(filename)) |> Seq.map (fun fileInfo -> sprintf "%s, %s, %d, %s" fileInfo.DirectoryName fileInfo.Name fileInfo.Length (fileInfo.CreationTime.ToShortDateString())) |> Seq.iteri (fun idx str -> printCsvToExcel (idx + 1) str)

更多推荐

.NET 4.0的F#和Excel集成(Visual Studio 2010 Beta 1)

本文发布于:2023-11-15 23:42:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1599013.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Excel   NET   Visual   Beta   Studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!