将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
最满意答案
也许这样的话会非常习惯(如果不是超级高效的话):
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是lss
或rss
的最长元素的长度。 一个更高效的版本(每个输入列表只调用一次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 ofrss
, and p is the length of the longest element oflss
orrss
. A more efficient version (which only callsfindIndex
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
Map
s 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 withliftA2 (,)
.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" ...
-
Haskell列表帮助!(Haskell list help!)[2022-07-23]
为图像使用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 ...
-
浏览Haskell中的列表(Going through a list in Haskell)[2022-11-06]
你可以使用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。 有关“保险丝”的详细信息,请参 ...
-
Haskell平等约束(Haskell Equality Constraint)[2022-02-17]
啊,键入家庭和非注入。 这是正在发生的事情:我们正在尝试打字检查 f { fieldView = (injectClass $ fieldView f)} 问题不在于injectClass可能会改变m是什么。 问题是它不知道 m是什么。 它的输入, fieldView f和上下文,设置fieldView f的fieldView字段,都只告诉它HandlerSite m是什么,而简单的事实是你无法弄清楚m是从那里得到的。 就像你有以下内容一样: type family F a type instance F ... -
在haskell中列出理解(List Comprehension in haskell)[2022-09-18]
如果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 ...