首页 \ 问答 \ 将ASP.Net网格数据输出到excel wo第三方dll(Export ASP.Net grid data to excel w.o. third party dll)

将ASP.Net网格数据输出到excel wo第三方dll(Export ASP.Net grid data to excel w.o. third party dll)

我想在不使用任何第三方DLL的情况下将网格数据从ASP.Net网页导出到Excel。

任何人都可以告诉我该怎么做?


I want to export grid data from ASP.Net webpage to Excel without using any third party dll.

can anybody tell me how to do it ?


原文:https://stackoverflow.com/questions/13681062
更新时间:2021-07-21 15:07

最满意答案

也许这样的话会非常习惯(如果不是超级高效的话):

import Data.List
eqElem l r lss rss =
    [ (ls, rs)
    | ls <- lss
    , rs <- rss
    , findIndex (l==) ls == findIndex (r==) rs
    ]

在ghci中:

> mapM_ print $ eqElem 2 "c" [[3,1,2,4],[1,4,2,3],[1,3,4,2]] [["a","b","c","d"],["d","a","c","b"],["c","b","a","d"],["d","b","c","a"]]
([3,1,2,4],["a","b","c","d"])
([3,1,2,4],["d","a","c","b"])
([3,1,2,4],["d","b","c","a"])
([1,4,2,3],["a","b","c","d"])
([1,4,2,3],["d","a","c","b"])
([1,4,2,3],["d","b","c","a"])

这有两个效率问题:1.重复计算输入列表中输入元素的位置,2.重复遍历所有输入列表对。 所以这种方式是O(mnp),其中m是lss的长度,n是rss的长度,p是lssrss的最长元素的长度。 一个更高效的版本(每个输入列表只调用一次findIndex ,并迭代少数几个列表对象; O(mn + mp + np + m log(m)+ n log(n)))如下所示:

import Control.Applicative
import qualified Data.Map as M

eqElem l r lss rss
    = concat . M.elems
    $ M.intersectionWith (liftA2 (,)) (index l lss) (index r rss)
    where
    index v vss = M.fromListWith (++) [(findIndex (v==) vs, [vs]) | vs <- vss]

基本思想是构建Map ,它告诉哪些输入列表在哪些位置上具有给定的元素。 然后,这两个映射的交集排列了具有相同位置的给定元素的输入列表,因此我们可以使用liftA2 (,)获取值的笛卡尔乘积。

再次在ghci中:

> mapM_ print $ eqElem 2 "c" [[3,1,2,4],[1,4,2,3],[1,3,4,2]] [["a","b","c","d"],["d","a","c","b"],["c","b","a","d"],["d","b","c","a"]]
([1,4,2,3],["d","b","c","a"])
([1,4,2,3],["d","a","c","b"])
([1,4,2,3],["a","b","c","d"])
([3,1,2,4],["d","b","c","a"])
([3,1,2,4],["d","a","c","b"])
([3,1,2,4],["a","b","c","d"])

Probably something like this would be very idiomatic (if not super efficient):

import Data.List
eqElem l r lss rss =
    [ (ls, rs)
    | ls <- lss
    , rs <- rss
    , findIndex (l==) ls == findIndex (r==) rs
    ]

In ghci:

> mapM_ print $ eqElem 2 "c" [[3,1,2,4],[1,4,2,3],[1,3,4,2]] [["a","b","c","d"],["d","a","c","b"],["c","b","a","d"],["d","b","c","a"]]
([3,1,2,4],["a","b","c","d"])
([3,1,2,4],["d","a","c","b"])
([3,1,2,4],["d","b","c","a"])
([1,4,2,3],["a","b","c","d"])
([1,4,2,3],["d","a","c","b"])
([1,4,2,3],["d","b","c","a"])

This has two efficiency problems: 1. it recomputes the location of the input elements in the input lists repeatedly, and 2. it iterates over all pairs of input lists. So this way is O(mnp) where m is the length of lss, n is the length of rss, and p is the length of the longest element of lss or rss. A more efficient version (which only calls findIndex once per input list, and iterates over many fewer pairs of lists; O(mn+mp+np+m log(m)+n log(n))) would look like this:

import Control.Applicative
import qualified Data.Map as M

eqElem l r lss rss
    = concat . M.elems
    $ M.intersectionWith (liftA2 (,)) (index l lss) (index r rss)
    where
    index v vss = M.fromListWith (++) [(findIndex (v==) vs, [vs]) | vs <- vss]

The basic idea is to build up Maps which tell which input lists have the given elements at which positions. Then the intersection of these two maps line up input lists that have the given elements at the same positions, so we can just take the Cartesian product of the values there with liftA2 (,).

Again in ghci:

> mapM_ print $ eqElem 2 "c" [[3,1,2,4],[1,4,2,3],[1,3,4,2]] [["a","b","c","d"],["d","a","c","b"],["c","b","a","d"],["d","b","c","a"]]
([1,4,2,3],["d","b","c","a"])
([1,4,2,3],["d","a","c","b"])
([1,4,2,3],["a","b","c","d"])
([3,1,2,4],["d","b","c","a"])
([3,1,2,4],["d","a","c","b"])
([3,1,2,4],["a","b","c","d"])

相关问答

更多
  • 也许这样的话会非常习惯(如果不是超级高效的话): import Data.List eqElem l r lss rss = [ (ls, rs) | ls <- lss , rs <- rss , findIndex (l==) ls == findIndex (r==) rs ] 在ghci中: > mapM_ print $ eqElem 2 "c" [[3,1,2,4],[1,4,2,3],[1,3,4,2]] [["a","b","c","d"],["d" ...
  • 为图像使用print以外的名称,以避免与Prelude的print冲突。 type Pixel = Int type Row = [Pixel] type PixelImage = [Row] img :: PixelImage img = [[208,152,240,29],[0,112,255,59],[76,185,0,152]] 这是一种效率低下的表现形式,但它可以用于学习练习。 你可以打印一个PixelImage其中的行堆叠在一起,在源代码的顶部有一些导入和一个I / O操作: import ...
  • lookUp :: [String] -> String -> Int lookUp [] s = error "..." -- An empty list does not contain _anything_, in -- particular not the string you're looking for. lookUp (x:xs) s -- We've eliminated the empty case, which guaran ...
  • 你可以使用zipWith3 : zipWith3 (\a b c -> [a,b,c]) xs (drop 1 xs) (drop 2 xs) 但是,当人们可以概括时,为什么要止步呢? subLists :: Int -> [a] -> [[a]] subLists n xs = let ts = take n xs in if length ts == n then ts : subLists n (tail xs) else [] 这个解决方案可以 ...
  • 我们正在寻找的函数签名是[[a]] -> [a] ,如果我们检查hoogle,我们会看到concat是我们正在寻找的。 而在这种情况下,列表理解是不必要的,因为我们只是迭代每个项目,所以我们真的只想做一个map 。 所以既然组合map和concat非常普遍,我们可以写出来 concatMap (\x -> nPrint x x) [1..] 如果你对haskell很concatMap你可以忽略它,但是因为列表monad是用concatMap定义的, concatMap我们也可以写 [1..] >>= \x ...
  • 问题在于 data Trainable a b = forall n . Floating n => Trainable ([n] -> a -> b) (a -> b -> [n] -> n) 意味着在 Trainable transfer cost 使用的类型n丢失。 所有已知的是,有一种类型的Guessme Floating实例 transfer :: [Guessme] -> a -> b cost :: a -> b -> [Guessme] -> Guessme 您可以使用仅适用于Com ...
  • Haskell非常擅长对列表进行优化,但不是您描述的类型。 Haskell对列表没有“特殊”处理 - 它们就像其他普通的Haskell类型一样,虽然有一些内置的语法糖。 没什么特别的 data List a = Nil | Cons a (List a) 将会。 Haskell使用所谓的foldr / build fusion来优化列表,例如优化map f (filter p list)这样它就不会为filter生成中间列表,而是在同一次遍历中同时执行map和filter。 有关“保险丝”的详细信息,请参 ...
  • 啊,键入家庭和非注入。 这是正在发生的事情:我们正在尝试打字检查 f { fieldView = (injectClass $ fieldView f)} 问题不在于injectClass可能会改变m是什么。 问题是它不知道 m是什么。 它的输入, fieldView f和上下文,设置fieldView f的fieldView字段,都只告诉它HandlerSite m是什么,而简单的事实是你无法弄清楚m是从那里得到的。 就像你有以下内容一样: type family F a type instance F ...
  • 如果a = [1, 2, 3]和b = [4, 5, 6] ,你可以这样做: map (\x -> a ++ [x]) b 对于b每个元素, map将应用函数\x -> a ++ [x] 。 此函数连接两个列表a和[x] 。 您也可以将其写为列表理解: [a ++ [x] | x <- b] If a = [1, 2, 3] and b = [4, 5, 6], you can do something like this: map (\x -> a ++ [x]) b For each elemen ...
  • 作为另一个答案的后续内容,这里有一些东西可以让你在没有任何重叠实例的情况下编写ToText。 它使用我最喜欢的技巧 - 将闭合类型系列混合到datakinds作为典型类型类的“选择”机制(注意:甚至不使用函数依赖,更不用重叠实例)来合成实际代码: {-# LANGUAGE TypeFamilies, DataKinds, MultiParamTypeClasses, FlexibleInstances, ScopedTypeVariables, FlexibleContexts #-} import Da ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)