简体   繁体   English

使用沿X,Y,Z轴线的数据创建Apache POI Excel

[英]Apache POI Excel creation with data along X,Y,Z axis lines

I'm working on creating an excel using XSSF. 我正在使用XSSF创建一个excel。

This excel will contain data in the top 3 rows (Imagine this as x axis). 此excel将在前3行中包含数据(将其想象为x轴)。 I also have data filled in 2 left hand columns (Imagine this as Y axis). 我也将数据填充在2个左手栏中(将其想象为Y轴)。

Now, i have to add a flag across the sheet indicating a match between x & y axis values (Imagine z axis). 现在,我必须在工作表上添加一个标志,指示x和y轴值(想象z轴)之间的匹配。

Eg if i have values on x axis: x1 (Cell:D1),x2,x3,x4 etc... on Y axis: Y1, Y2, Y3(Cell:12C) )etc. 例如,如果我在x轴上有值:Y1轴上有x1(Cell:D1),x2,x3,x4等...,Y1,Y2,Y3(Cell:12C))等。

If x1 == Y3, I have a mark the common cell (D12) with 'X'. 如果x1 == Y3,我用'X'标记公共单元格(D12)。

I have all this data in Linkedhashmap's. 我所有这些数据都在Linkedhashmap中。 X-axis data in one linkedhashmap, y-axis in another and i also have the information, which x values equals to which y value in another linkedhashamp. 一个已链接哈希表中的X轴数据,另一个链接哈希表中的y轴,我也有信息,其中x值等于另一个已链接哈希表中的y值。 So i have to loop over these hashmaps and create an excel sheet. 因此,我必须遍历这些哈希图并创建一个Excel工作表。

My question : I have this matching info hashmap with column (x-axis) data as Key and Row data as values. 我的问题 :我有此匹配的信息哈希图,其中列(x轴)数据作为键,行数据作为值。 So, i have to traverse the sheet column wise. 因此,我必须明智地遍历工作表列。 (X1->Y3,Y100,Y123, X2->Y2,Y79,Y500). (X1-> Y3,Y100,Y123,X2-> Y2,Y79,Y500)。

Is this good approach or Should i reverse the key and values in the hasmap, Considering performance ? 考虑到性能,这是一种好方法还是应该在hasmap中反转键和值?

I have limited (ranging:100-5000) values on x-axis (the reason for keep them on x-asixs) while i have 1 million rows/values (on Y-axis). 我在x轴上限制了(范围:100-5000)值(将它们保留在x-asax上的原因),而我却有100万行/值(在Y轴上)。

Open to any other suggestions you may have, please suggest. 欢迎您提出其他建议。

Thanks a lot for your help. 非常感谢你的帮助。

PS I have experience working with excel and also a bit of experience working with POI, I know the basics and i have created excel sheets before but with limited data and which always goes row wise and not like this multidimensional. PS:我有使用excel的经验,也有使用POI的经验,我知道一些基础知识,并且我之前创建过excel表格,但是数据有限,而且总是按行排列,而不是多维。

I think I would use 我想我会用

cell.setCellFormula(formula_str);

with a formula like 像这样的公式

=if(a1=b3, "", "MISMATCH") 

or however its supposed to work. 或者它应该工作。 That way you let Excel do the work rather than having to make hashmaps and all kinds of convoluted things in your Java code. 这样,您就可以让Excel完成工作,而不必在Java代码中创建哈希图和各种复杂的东西。 Also that way, when a user updates the Excel it will update for them. 同样,当用户更新Excel时,它将为他们更新。 Users won't like it if your calculations don't update when they change the data in Excel. 如果您在Excel中更改数据时您的计算没有更新,则用户将不喜欢它。

cell.setCellFormula("IF(A1=B3, \"\", \"MISMATCH\")");

To create your column or row of forumulas you just need a loop to change the numbers from A1, B3 to whatever as you traverse and add the formula cells. 要创建您的论坛列或行,您只需要一个循环即可将数字从A1,B3更改为遍历并添加公式单元格的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM