The catalyst wave open Excel 46 - arranged in a matrix pattern a plurality of Techniques

Cipian corresponding functions by: a first wave 10 - Express graphic objects are arranged Worksheet - Simple Book https://www.jianshu.com/p/eab71f2969a6

In the Excel object model, the width of the columns is not generally expected and as is the row height in points, but by the character width character size currently set for the unit, resulting in the column width is adjusted according to the image size there is no way to adjust in place, there is always a little bit errors.

Arranged in a pattern in the process described in this post, will be troubled by this indirect manner using cyclic adjust column width, or with the current value Width ColumnWidth and two ways to count ratio between them, but there is still an error , so Excel catalyst picture series function, are used instead of container PictureBox picture aspect ratio of the solution to the problem.

All selected graphics arranged in columns from top to bottom or from left to right by rows in two ways. All the basic information required to record the pattern as top, left, height, width and other attributes, a new entity class to store this information, using a specific generic in .Net to solve it.

    class ShapeInfo
    {
        public int ShapeIndex { get; set; }
        public Single Height { get; set; }
        public Single Width { get; set; }
        public Excel.Range TopLeftCell { get; set; }

        public Single Top { get; set; }
        public Single Left { get; set; }
    }

The following methods and then by the master, the graphics information into a set of List, the maximum pattern width and removed from the column width as the pattern arrangement.

Then a While loop, so that the current maximum column width and column width equal to the graphics, because the conversion factor issue, there will always be a little bit of small errors.

Adjust the graphic display is also important shp.Placement = Excel.XlPlacement.xlMoveAndSize; This property ensures the user to edit line width, pattern will follow automatically reduced amplification.

Height, use of graphics and cells of highly fit, to facilitate post adjustment automatically adjusts the high ranks, there will be the size of the original graphic slightly out, if the non-image, little deformation impact.
shp.Height = (Single) actSht.Range [shp.TopLeftCell , shp.BottomRightCell] .Height;

Finally, with different graphical tired, simply by changing its attributes to Top, the next Top Top property positioned in the current position + the current height of the pattern.

dstRangeTop = dstRangeTop + shp.Height;

 public static void ArrangeShapeByCol(Excel.ShapeRange shpSelected, Excel.Range dstRange)
        {
            Excel.Worksheet actSht = dstRange.Worksheet;
            List<Entity.ShapeInfo> ShapeLists = GetShapelist(shpSelected);

            int increaseColwidthStep = 0;
            Single shapMaxWidth = ShapeLists.Max(s => s.Width);
            while (dstRange.Width < shapMaxWidth)
            {
                increaseColwidthStep++;
                dstRange.EntireColumn.ColumnWidth = dstRange.EntireColumn.ColumnWidth + increaseColwidthStep;
            }

            Single dstRangeTop = (Single)dstRange.Top;
            foreach (Entity.ShapeInfo shpInfo in ShapeLists.OrderBy(s => s.Top))
            {
                Excel.Shape shp = shpSelected.Item(shpInfo.ShapeIndex);
                shp.Top = dstRangeTop;
                shp.Left = (Single)dstRange.Left;
                shp.Width = (Single)dstRange.Width;
                shp.Height = (Single)actSht.Range[shp.TopLeftCell, shp.BottomRightCell].Height;
                shp.Placement = Excel.XlPlacement.xlMoveAndSize;
                //把top的值改写为top+此次循环的shp的高度设置值
                dstRangeTop = dstRangeTop + shp.Height;
            }

        }

Finally completed the alignment pattern, slightly modified a little

Epilogue

While this post is not difficult to achieve in the way VBA, but the use of generics in .Net programming environment, Linq query and other characteristics, in the process of writing the code will become very elegant, and natural thinking is very close to the amount of code it also streamlined to complete, so that we see the development of efficient VSTO under way again.

Technical exchange QQ group

QQ group name: Excel catalyst open discussion groups, QQ group number: 788 145 319
Excel catalyst dimensional code open source discussion groups

About Excel catalyst

Excel catalyst name, first a public micro-channel number, then shun its name, officially launched the Excel plug-in, plug-continuous updates, the update cycle depends on my time may be able to fight for one week on a line function modules. Excel catalyst plug-permanent commitment to individual users free of charge!

Excel catalyst plugin uses the latest deployment of technology, once installed, all future updates automatically update is complete, no need to repeat concerns updates, manually download the installation package to reinstall, you can always keep the latest version with a single installation!

The catalyst Excel plug-in download link: https://pan.baidu.com/s/1Iz2_NZJ8v7C9eqhNjdnP3Q

Contact the author

No public

Named catalyst , due to strong itself, not everyone can immediately enjoy Excel, most people are still at the stage of the child's Excel software, the mind is very clear and want to achieve results, and experts who also have achieved it, that is, how to get yourself out Dounong, or worse, you do not know what Excel can do while staying in constant repetition, mechanically, manually doing data, spend countless youth years. So spawned whether as a medium, so that the majority of Excel users can instantly ignite the explosion point Excel, without the need desperately struggled day and night to learn skills, brain burn senior complex functions, going on from entry to give up the road.

最后Excel功能强大,其实还需树立一个观点,不是所有事情都要交给Excel去完成,也不是所有事情Excel都是十分胜任的,外面的世界仍然是一个广阔的世界,Excel只是其中一枚耀眼的明星,还有其他更多同样精彩强大的技术、工具等。*Excel催化剂也将借力这些其他技术,让Excel能够发挥更强大的爆发!

关于Excel催化剂作者

姓名:李伟坚,从事数据分析工作多年(BI方向),一名同样在路上的学习者。
服务过行业:零售特别是鞋服类的零售行业,电商(淘宝、天猫、京东、唯品会)

技术路线从一名普通用户,通过Excel软件的学习,从此走向数据世界,非科班IT专业人士。
历经重重难关,终于在数据的道路上达到技术平原期,学习众多的知识不再太吃力,同时也形成了自己的一套数据解决方案(数据采集、数据加工清洗、数据多维建模、数据报表展示等)。

擅长技术领域:Excel等Office家族软件、VBA&VSTO的二次开发、Sqlserver数据库技术、Sqlserver的商业智能BI技术、Powerbi技术、云服务器布署技术等等。

2018年开始职业生涯作了重大调整,从原来的正职工作,转为自由职业者,暂无固定收入,暂对前面道路不太明朗,苦重新回到正职工作,对Excel催化剂的运营和开发必定受到很大的影响(正职工作时间内不可能维护也不可能随便把工作时间内的成果公布于外,工作外的时间也十分有限,因已而立之年,家庭责任重大)。

And the majority of advocates with expectations: Excel catalyst has been able to run down, I have the benefit of the group were able to support ( multi-message encouragement, friend circle under forwarded the recommendation under small a reward and the most focused and where the company can and recommended recommended peers, so I can maximize the value of technology in your company to achieve a win-win (you can imagine how the data is preliminary consultant or small projects to develop forms of cooperation).

Guess you like

Origin www.cnblogs.com/ExcelCuiHuaJi/p/11225089.html