Beispiel #1
0
        GetAttributeColumn
        (
            ListObject oTable,
            String sAttribute,
            out ListColumn oAttributeColumn,
            out Range oAttributeColumnData
        )
        {
            Debug.Assert(oTable != null);
            Debug.Assert(!String.IsNullOrEmpty(sAttribute));

            if (!ExcelTableUtil.TryGetTableColumn(oTable, sAttribute,
                                                  out oAttributeColumn))
            {
                if (!ExcelTableUtil.TryAddTableColumn(oTable, sAttribute,
                                                      ExcelTableUtil.AutoColumnWidth, null, out oAttributeColumn))
                {
                    goto CannotGetColumn;
                }

                // Wrap the text in the new column's header.

                ExcelTableUtil.WrapTableColumnHeader(oAttributeColumn);

                // This sometimes wraps a single-word header.  Fix it.

                oAttributeColumn.Range.EntireColumn.AutoFit();
            }

            if (ExcelTableUtil.TryGetTableColumnData(oAttributeColumn,
                                                     out oAttributeColumnData))
            {
                // Success.

                return;
            }

CannotGetColumn:

            throw new WorkbookFormatException(
                      "The " + sAttribute + " column couldn't be added."
                      );
        }
Beispiel #2
0
        TryGetRequiredColumnInformation
        (
            GraphMetricColumn oGraphMetricColumn,
            ListObject oTable,
            out Range oVisibleColumnData
        )
        {
            Debug.Assert(oGraphMetricColumn != null);
            Debug.Assert(oTable != null);
            AssertValid();

            oVisibleColumnData = null;

            // Add the specified column if it's not already present.

            String sColumnName  = oGraphMetricColumn.ColumnName;
            String sColumnStyle = oGraphMetricColumn.Style;

            Microsoft.Office.Interop.Excel.ListColumn oColumn;

            if (
                !ExcelTableUtil.TryGetTableColumn(oTable, sColumnName, out oColumn)
                &&
                !ExcelTableUtil.TryAddTableColumn(oTable, sColumnName,
                                                  oGraphMetricColumn.ColumnWidthChars, sColumnStyle, out oColumn)
                )
            {
                // Give up.

                return(false);
            }

            Range oColumnData;

            if (!ExcelTableUtil.TryGetTableColumnData(oTable, sColumnName,
                                                      out oColumnData))
            {
                return(false);
            }

            ExcelUtil.SetRangeStyle(oColumnData, sColumnStyle);

            String sNumberFormat = oGraphMetricColumn.NumberFormat;

            if (sNumberFormat != null)
            {
                oColumnData.NumberFormat = sNumberFormat;
            }

            // Wrapping text makes Range.set_Value() very slow, so turn it off.

            oColumn.Range.WrapText = false;

            // But wrap the text in the column's header.

            ExcelTableUtil.WrapTableColumnHeader(oColumn);

            // Get the visible range.

            if (!ExcelUtil.TryGetVisibleRange(oColumnData,
                                              out oVisibleColumnData))
            {
                return(false);
            }

            return(true);
        }