设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

12下一页
返回列表 发新帖
查看: 8671|回复: 13
打印 上一主题 下一主题

【练习】从最基本的代码框架开始撸

[复制链接]
跳转到指定楼层
1#
发表于 2014-2-24 14:31:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 faunus 于 2014-2-26 11:01 编辑
  1.         private void ThisAddIn_Startup(object sender, System.EventArgs e)
  2.         {
  3.             //Application 的三种调用形式
  4.             Excel.Application app;

  5.             app = Application;
  6.             app = this.Application;
  7.             app = Globals.ThisAddIn.Application;//在RIBBON中,只能这样调用。

  8.             //获得基本对像
  9.             Excel.Workbook book = app.ActiveWorkbook;
  10.             Excel.Worksheet sh = book.ActiveSheet;

  11.             //单元格对像
  12.             Excel.Range rA1 = sh.Cells[1, 1];

  13.             //开始随便撸
  14.             rA1.Value = "hello";
  15.             rA1.Formula = "=1+100";
  16.         }
复制代码

【以上代码在 ,启动事件中撸】

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2014-2-24 14:33:17 | 只看该作者
本帖最后由 faunus 于 2014-2-24 14:35 编辑

//在RIBBON中,只能这样调用。
app = Globals.ThisAddIn.Application;

  1.         private void button4_Click(object sender, RibbonControlEventArgs e)
  2.         {
  3.             //Application 的三种调用形式
  4.             Excel.Application app;
  5.             app = Globals.ThisAddIn.Application;//在RIBBON中,只能这样调用。

  6.             //获得基本对像
  7.             Excel.Workbook book = app.ActiveWorkbook;
  8.             Excel.Worksheet sh = book.ActiveSheet;

  9.             //单元格对像
  10.             Excel.Range rA1 = sh.Cells[1, 1];

  11.             //开始随便撸
  12.             rA1.Value = "hello";
  13.             rA1.Formula = "=1+100";
  14.         }
复制代码


【以上代码在 ,RIBBON事件中撸】
请注意两者区别。

3#
发表于 2014-2-24 14:37:52 | 只看该作者
第9,10行,我VS报错..缺少强制类型转换

评分

参与人数 1V币 +1 收起 理由
faunus + 1 (V币)代码练习跟贴(1分)

查看全部评分

4#
 楼主| 发表于 2014-2-24 14:48:28 | 只看该作者
cc1027cc 发表于 2014-2-24 14:37
第9,10行,我VS报错..缺少强制类型转换

我这里第九、十行,没有代码。
你方便贴一下。
5#
 楼主| 发表于 2014-2-24 14:59:15 | 只看该作者
  1.     // 摘要:
  2.     //     Represents a cell, a row, a column, a selection of cells containing one or
  3.     //     more contiguous blocks of cells, or a 3-D range.
  4.     [Guid("00020846-0000-0000-C000-000000000046")]
  5.     [InterfaceType(2)]
  6.     [TypeLibType(4096)]
  7.     public interface Range : IEnumerable
复制代码


RANGE的定义,可以是单元格、行、列、区域或三维引用
可以每一种形式都试试。
6#
 楼主| 发表于 2014-2-24 15:02:41 | 只看该作者
  1.         dynamic AddIndent { get; set; }
  2.         bool AllowEdit { get; }
  3.         Application Application { get; }
  4.         Areas Areas { get; }
  5.         Borders Borders { get; }
  6.         Range Cells { get; }
  7.         int Column { get; }
  8.         Range Columns { get; }
  9.         dynamic ColumnWidth { get; set; }
  10.         Comment Comment { get; }
  11.         int Count { get; }
  12.         dynamic CountLarge { get; }
  13.         XlCreator Creator { get; }
  14.         Range CurrentArray { get; }
  15.         Range CurrentRegion { get; }
  16.         Range Dependents { get; }
  17.         Range DirectDependents { get; }
  18.         Range DirectPrecedents { get; }
  19.         DisplayFormat DisplayFormat { get; }
  20.         Range EntireColumn { get; }
  21.         Range EntireRow { get; }
  22.         Errors Errors { get; }
  23.         Font Font { get; }
  24.         FormatConditions FormatConditions { get; }
  25.         dynamic Formula { get; set; }
  26.         dynamic FormulaArray { get; set; }
  27.         dynamic FormulaHidden { get; set; }
  28.         XlFormulaLabel FormulaLabel { get; set; }
  29.         dynamic FormulaLocal { get; set; }
  30.         dynamic FormulaR1C1 { get; set; }
  31.         dynamic FormulaR1C1Local { get; set; }
  32.         dynamic HasArray { get; }
  33.         dynamic HasFormula { get; }
  34.         dynamic Height { get; }
  35.         dynamic Hidden { get; set; }
  36.         dynamic HorizontalAlignment { get; set; }
  37.         Hyperlinks Hyperlinks { get; }
  38.         string ID { get; set; }
  39.         dynamic IndentLevel { get; set; }
  40.         Interior Interior { get; }
  41.         dynamic Left { get; }
  42.         int ListHeaderRows { get; }
  43.         ListObject ListObject { get; }
  44.         XlLocationInTable LocationInTable { get; }
  45.         dynamic Locked { get; set; }
  46.         string MDX { get; }
  47.         Range MergeArea { get; }
  48.         dynamic MergeCells { get; set; }
  49.         dynamic Name { get; set; }
  50.         Range Next { get; }
  51.         dynamic NumberFormat { get; set; }
  52.         dynamic NumberFormatLocal { get; set; }
  53.         dynamic Orientation { get; set; }
  54.         dynamic OutlineLevel { get; set; }
  55.         int PageBreak { get; set; }
  56.         dynamic Parent { get; }
  57.         Phonetic Phonetic { get; }
  58.         Phonetics Phonetics { get; }
  59.         PivotCell PivotCell { get; }
  60.         PivotField PivotField { get; }
  61.         PivotItem PivotItem { get; }
  62.         PivotTable PivotTable { get; }
  63.         Range Precedents { get; }
  64.         dynamic PrefixCharacter { get; }
  65.         Range Previous { get; }
  66.         QueryTable QueryTable { get; }
  67.         int ReadingOrder { get; set; }
  68.         int Row { get; }
  69.         dynamic RowHeight { get; set; }
  70.         Range Rows { get; }
  71.         Actions ServerActions { get; }
  72.         dynamic ShowDetail { get; set; }
  73.         dynamic ShrinkToFit { get; set; }
  74.         SmartTags SmartTags { get; }
  75.         SoundNote SoundNote { get; }
  76.         SparklineGroups SparklineGroups { get; }
  77.         dynamic Style { get; set; }
  78.         dynamic Summary { get; }
  79.         dynamic Text { get; }
  80.         dynamic Top { get; }
  81.         dynamic UseStandardHeight { get; set; }
  82.         dynamic UseStandardWidth { get; set; }
  83.         Validation Validation { get; }
  84.         dynamic Value2 { get; set; }
  85.         dynamic VerticalAlignment { get; set; }
  86.         dynamic Width { get; }
  87.         Worksheet Worksheet { get; }
  88.         dynamic WrapText { get; set; }
  89.         XPath XPath { get; }
复制代码
7#
 楼主| 发表于 2014-2-24 15:04:07 | 只看该作者
  1. dynamic this[object RowIndex = Type.Missing, object ColumnIndex = Type.Missing] { get; set; }
  2. dynamic _PasteSpecial(XlPasteType Paste = XlPasteType.xlPasteAll, XlPasteSpecialOperation Operation = XlPasteSpecialOperation.xlPasteSpecialOperationNone, object SkipBlanks = Type.Missing, object Transpose = Type.Missing);
  3. dynamic _PrintOut(object From = Type.Missing, object To = Type.Missing, object Copies = Type.Missing, object Preview = Type.Missing, object ActivePrinter = Type.Missing, object PrintToFile = Type.Missing, object Collate = Type.Missing);
  4. dynamic Activate();
  5. Comment AddComment(object Text = Type.Missing);
  6. dynamic AdvancedFilter(XlFilterAction Action, object CriteriaRange = Type.Missing, object CopyToRange = Type.Missing, object Unique = Type.Missing);
  7. void AllocateChanges();
  8. dynamic ApplyNames(object Names = Type.Missing, object IgnoreRelativeAbsolute = Type.Missing, object UseRowColumnNames = Type.Missing, object OmitColumn = Type.Missing, object OmitRow = Type.Missing, XlApplyNamesOrder Order = XlApplyNamesOrder.xlRowThenColumn, object AppendLast = Type.Missing);
  9. dynamic ApplyOutlineStyles();
  10. string AutoComplete(string String);
  11. dynamic AutoFill(Range Destination, XlAutoFillType Type = XlAutoFillType.xlFillDefault);
  12. dynamic AutoFilter(object Field = Type.Missing, object Criteria1 = Type.Missing, XlAutoFilterOperator Operator = XlAutoFilterOperator.xlAnd, object Criteria2 = Type.Missing, object VisibleDropDown = Type.Missing);
  13. dynamic AutoFit();
  14. dynamic AutoFormat(XlRangeAutoFormat Format = XlRangeAutoFormat.xlRangeAutoFormatClassic1, object Number = Type.Missing, object Font = Type.Missing, object Alignment = Type.Missing, object Border = Type.Missing, object Pattern = Type.Missing, object Width = Type.Missing);
  15. dynamic AutoOutline();
  16. dynamic BorderAround(object LineStyle = Type.Missing, XlBorderWeight Weight = XlBorderWeight.xlThin, XlColorIndex ColorIndex = XlColorIndex.xlColorIndexAutomatic, object Color = Type.Missing);
  17. dynamic BorderAround2(object LineStyle = Type.Missing, XlBorderWeight Weight = XlBorderWeight.xlThin, XlColorIndex ColorIndex = XlColorIndex.xlColorIndexAutomatic, object Color = Type.Missing, object ThemeColor = Type.Missing);
  18. dynamic Calculate();
  19. dynamic CalculateRowMajorOrder();
  20. dynamic CheckSpelling(object CustomDictionary = Type.Missing, object IgnoreUppercase = Type.Missing, object AlwaysSuggest = Type.Missing, object SpellLang = Type.Missing);
  21. dynamic Clear();
  22. void ClearComments();
  23. dynamic ClearContents();
  24. dynamic ClearFormats();
  25. void ClearHyperlinks();
  26. dynamic ClearNotes();
  27. dynamic ClearOutline();
  28. Range ColumnDifferences(object Comparison);
  29. dynamic Consolidate(object Sources = Type.Missing, object Function = Type.Missing, object TopRow = Type.Missing, object LeftColumn = Type.Missing, object CreateLinks = Type.Missing);
  30. dynamic Copy(object Destination = Type.Missing);
  31. int CopyFromRecordset(object Data, object MaxRows = Type.Missing, object MaxColumns = Type.Missing);
  32. dynamic CopyPicture(XlPictureAppearance Appearance = XlPictureAppearance.xlScreen, XlCopyPictureFormat Format = XlCopyPictureFormat.xlPicture);
  33. dynamic CreateNames(object Top = Type.Missing, object Left = Type.Missing, object Bottom = Type.Missing, object Right = Type.Missing);
  34. dynamic CreatePublisher(object Edition = Type.Missing, XlPictureAppearance Appearance = XlPictureAppearance.xlScreen, object ContainsPICT = Type.Missing, object ContainsBIFF = Type.Missing, object ContainsRTF = Type.Missing, object ContainsVALU = Type.Missing);
  35. dynamic Cut(object Destination = Type.Missing);
  36. dynamic DataSeries(object Rowcol = Type.Missing, XlDataSeriesType Type = XlDataSeriesType.xlDataSeriesLinear, XlDataSeriesDate Date = XlDataSeriesDate.xlDay, object Step = Type.Missing, object Stop = Type.Missing, object Trend = Type.Missing);
  37. dynamic Delete(object Shift = Type.Missing);
  38. dynamic DialogBox();
  39. void Dirty();
  40. void DiscardChanges();
  41. dynamic EditionOptions(XlEditionType Type, XlEditionOptionsOption Option, object Name = Type.Missing, object Reference = Type.Missing, XlPictureAppearance Appearance = XlPictureAppearance.xlScreen, XlPictureAppearance ChartSize = XlPictureAppearance.xlScreen, object Format = Type.Missing);
  42. void ExportAsFixedFormat(XlFixedFormatType Type, object Filename = Type.Missing, object Quality = Type.Missing, object IncludeDocProperties = Type.Missing, object IgnorePrintAreas = Type.Missing, object From = Type.Missing, object To = Type.Missing, object OpenAfterPublish = Type.Missing, object FixedFormatExtClassPtr = Type.Missing);
  43. dynamic FillDown();
  44. dynamic FillLeft();
  45. dynamic FillRight();
  46. dynamic FillUp();
  47. Range Find(object What, object After = Type.Missing, object LookIn = Type.Missing, object LookAt = Type.Missing, object SearchOrder = Type.Missing, XlSearchDirection SearchDirection = XlSearchDirection.xlNext, object MatchCase = Type.Missing, object MatchByte = Type.Missing, object SearchFormat = Type.Missing);
  48. Range FindNext(object After = Type.Missing);
  49. Range FindPrevious(object After = Type.Missing);
  50. void FlashFill();
  51. dynamic FunctionWizard();
  52. string get_Address(object RowAbsolute = Type.Missing, object ColumnAbsolute = Type.Missing, XlReferenceStyle ReferenceStyle = XlReferenceStyle.xlA1, object External = Type.Missing, object RelativeTo = Type.Missing);
  53. string get_AddressLocal(object RowAbsolute = Type.Missing, object ColumnAbsolute = Type.Missing, XlReferenceStyle ReferenceStyle = XlReferenceStyle.xlA1, object External = Type.Missing, object RelativeTo = Type.Missing);
  54. Characters get_Characters(object Start = Type.Missing, object Length = Type.Missing);
  55. Range get_End(XlDirection Direction);
  56. dynamic get_Item(object RowIndex, object ColumnIndex = Type.Missing);
  57. Range get_Offset(object RowOffset = Type.Missing, object ColumnOffset = Type.Missing);
  58. Range get_Range(object Cell1, object Cell2 = Type.Missing);
  59. Range get_Resize(object RowSize = Type.Missing, object ColumnSize = Type.Missing);
  60. dynamic get_Value(object RangeValueDataType = Type.Missing);
复制代码


8#
 楼主| 发表于 2014-2-24 15:04:33 | 只看该作者
  1. IEnumerator GetEnumerator();
  2. bool GoalSeek(object Goal, Range ChangingCell);
  3. dynamic Group(object Start = Type.Missing, object End = Type.Missing, object By = Type.Missing, object Periods = Type.Missing);
  4. dynamic Insert(object Shift = Type.Missing, object CopyOrigin = Type.Missing);
  5. void InsertIndent(int InsertAmount);
  6. dynamic Justify();
  7. dynamic ListNames();
  8. void Merge(object Across = Type.Missing);
  9. dynamic NavigateArrow(object TowardPrecedent = Type.Missing, object ArrowNumber = Type.Missing, object LinkNumber = Type.Missing);
  10. string NoteText(object Text = Type.Missing, object Start = Type.Missing, object Length = Type.Missing);
  11. dynamic Parse(object ParseLine = Type.Missing, object Destination = Type.Missing);
  12. dynamic PasteSpecial(XlPasteType Paste = XlPasteType.xlPasteAll, XlPasteSpecialOperation Operation = XlPasteSpecialOperation.xlPasteSpecialOperationNone, object SkipBlanks = Type.Missing, object Transpose = Type.Missing);
  13. dynamic PrintOut(object From = Type.Missing, object To = Type.Missing, object Copies = Type.Missing, object Preview = Type.Missing, object ActivePrinter = Type.Missing, object PrintToFile = Type.Missing, object Collate = Type.Missing, object PrToFileName = Type.Missing);
  14. dynamic PrintOutEx(object From = Type.Missing, object To = Type.Missing, object Copies = Type.Missing, object Preview = Type.Missing, object ActivePrinter = Type.Missing, object PrintToFile = Type.Missing, object Collate = Type.Missing, object PrToFileName = Type.Missing);
  15. dynamic PrintPreview(object EnableChanges = Type.Missing);
  16. void RemoveDuplicates(object Columns = Type.Missing, XlYesNoGuess Header = XlYesNoGuess.xlNo);
  17. dynamic RemoveSubtotal();
  18. bool Replace(object What, object Replacement, object LookAt = Type.Missing, object SearchOrder = Type.Missing, object MatchCase = Type.Missing, object MatchByte = Type.Missing, object SearchFormat = Type.Missing, object ReplaceFormat = Type.Missing);
  19. Range RowDifferences(object Comparison);
  20. dynamic Run(object Arg1 = Type.Missing, object Arg2 = Type.Missing, object Arg3 = Type.Missing, object Arg4 = Type.Missing, object Arg5 = Type.Missing, object Arg6 = Type.Missing, object Arg7 = Type.Missing, object Arg8 = Type.Missing, object Arg9 = Type.Missing, object Arg10 = Type.Missing, object Arg11 = Type.Missing, object Arg12 = Type.Missing, object Arg13 = Type.Missing, object Arg14 = Type.Missing, object Arg15 = Type.Missing, object Arg16 = Type.Missing, object Arg17 = Type.Missing, object Arg18 = Type.Missing, object Arg19 = Type.Missing, object Arg20 = Type.Missing, object Arg21 = Type.Missing, object Arg22 = Type.Missing, object Arg23 = Type.Missing, object Arg24 = Type.Missing, object Arg25 = Type.Missing, object Arg26 = Type.Missing, object Arg27 = Type.Missing, object Arg28 = Type.Missing, object Arg29 = Type.Missing, object Arg30 = Type.Missing);
  21. dynamic Select();
  22. void set_Item(object RowIndex, object ColumnIndex = Type.Missing, object value = Type.Missing);
  23. void set_Value(object RangeValueDataType = Type.Missing, object value = Type.Missing);
  24. void SetPhonetic();
  25. dynamic Show();
  26. dynamic ShowDependents(object Remove = Type.Missing);
  27. dynamic ShowErrors();
  28. dynamic ShowPrecedents(object Remove = Type.Missing);
  29. dynamic Sort(object Key1 = Type.Missing, XlSortOrder Order1 = XlSortOrder.xlAscending, object Key2 = Type.Missing, object Type = Type.Missing, XlSortOrder Order2 = XlSortOrder.xlAscending, object Key3 = Type.Missing, XlSortOrder Order3 = XlSortOrder.xlAscending, XlYesNoGuess Header = XlYesNoGuess.xlNo, object OrderCustom = Type.Missing, object MatchCase = Type.Missing, XlSortOrientation Orientation = XlSortOrientation.xlSortRows, XlSortMethod SortMethod = XlSortMethod.xlPinYin, XlSortDataOption DataOption1 = XlSortDataOption.xlSortNormal, XlSortDataOption DataOption2 = XlSortDataOption.xlSortNormal, XlSortDataOption DataOption3 = XlSortDataOption.xlSortNormal);
  30. dynamic SortSpecial(XlSortMethod SortMethod = XlSortMethod.xlPinYin, object Key1 = Type.Missing, XlSortOrder Order1 = XlSortOrder.xlAscending, object Type = Type.Missing, object Key2 = Type.Missing, XlSortOrder Order2 = XlSortOrder.xlAscending, object Key3 = Type.Missing, XlSortOrder Order3 = XlSortOrder.xlAscending, XlYesNoGuess Header = XlYesNoGuess.xlNo, object OrderCustom = Type.Missing, object MatchCase = Type.Missing, XlSortOrientation Orientation = XlSortOrientation.xlSortRows, XlSortDataOption DataOption1 = XlSortDataOption.xlSortNormal, XlSortDataOption DataOption2 = XlSortDataOption.xlSortNormal, XlSortDataOption DataOption3 = XlSortDataOption.xlSortNormal);
  31. void Speak(object SpeakDirection = Type.Missing, object SpeakFormulas = Type.Missing);
  32. Range SpecialCells(XlCellType Type, object Value = Type.Missing);
  33. dynamic SubscribeTo(string Edition, XlSubscribeToFormat Format = XlSubscribeToFormat.xlSubscribeToText);
  34. dynamic Subtotal(int GroupBy, XlConsolidationFunction Function, object TotalList, object Replace = Type.Missing, object PageBreaks = Type.Missing, XlSummaryRow SummaryBelowData = XlSummaryRow.xlSummaryBelow);
  35. dynamic Table(object RowInput = Type.Missing, object ColumnInput = Type.Missing);
  36. dynamic TextToColumns(object Destination = Type.Missing, XlTextParsingType DataType = XlTextParsingType.xlDelimited, XlTextQualifier TextQualifier = XlTextQualifier.xlTextQualifierDoubleQuote, object ConsecutiveDelimiter = Type.Missing, object Tab = Type.Missing, object Semicolon = Type.Missing, object Comma = Type.Missing, object Space = Type.Missing, object Other = Type.Missing, object OtherChar = Type.Missing, object FieldInfo = Type.Missing, object DecimalSeparator = Type.Missing, object ThousandsSeparator = Type.Missing, object TrailingMinusNumbers = Type.Missing);
  37. dynamic Ungroup();
  38. void UnMerge();
复制代码


【共计187个属性、方法等】
9#
发表于 2014-2-24 15:11:09 | 只看该作者
faunus 发表于 2014-2-24 14:48
我这里第九、十行,没有代码。
你方便贴一下。

9,12.我额.

点击这里给我发消息

10#
发表于 2014-2-24 15:27:20 | 只看该作者
已撸,哇咔咔咔

评分

参与人数 1V币 +1 收起 理由
faunus + 1 (V币)代码练习跟贴(1分)

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-4-29 06:25 , Processed in 0.088358 second(s), 37 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表