worksheet.h 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119
  1. /*
  2. * libxlsxwriter
  3. *
  4. * Copyright 2014-2018, John McNamara, [email protected]. See LICENSE.txt.
  5. */
  6. /**
  7. * @page worksheet_page The Worksheet object
  8. *
  9. * The Worksheet object represents an Excel worksheet. It handles
  10. * operations such as writing data to cells or formatting worksheet
  11. * layout.
  12. *
  13. * See @ref worksheet.h for full details of the functionality.
  14. *
  15. * @file worksheet.h
  16. *
  17. * @brief Functions related to adding data and formatting to a worksheet.
  18. *
  19. * The Worksheet object represents an Excel worksheet. It handles
  20. * operations such as writing data to cells or formatting worksheet
  21. * layout.
  22. *
  23. * A Worksheet object isn't created directly. Instead a worksheet is
  24. * created by calling the workbook_add_worksheet() function from a
  25. * Workbook object:
  26. *
  27. * @code
  28. * #include "xlsxwriter.h"
  29. *
  30. * int main() {
  31. *
  32. * lxw_workbook *workbook = workbook_new("filename.xlsx");
  33. * lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
  34. *
  35. * worksheet_write_string(worksheet, 0, 0, "Hello Excel", NULL);
  36. *
  37. * return workbook_close(workbook);
  38. * }
  39. * @endcode
  40. *
  41. */
  42. #ifndef __LXW_WORKSHEET_H__
  43. #define __LXW_WORKSHEET_H__
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <stdint.h>
  47. #include <string.h>
  48. #include "shared_strings.h"
  49. #include "chart.h"
  50. #include "drawing.h"
  51. #include "common.h"
  52. #include "format.h"
  53. #include "utility.h"
  54. #define LXW_ROW_MAX 1048576
  55. #define LXW_COL_MAX 16384
  56. #define LXW_COL_META_MAX 128
  57. #define LXW_HEADER_FOOTER_MAX 255
  58. #define LXW_MAX_NUMBER_URLS 65530
  59. #define LXW_PANE_NAME_LENGTH 12 /* bottomRight + 1 */
  60. /* The Excel 2007 specification says that the maximum number of page
  61. * breaks is 1026. However, in practice it is actually 1023. */
  62. #define LXW_BREAKS_MAX 1023
  63. /** Default column width in Excel */
  64. #define LXW_DEF_COL_WIDTH (double)8.43
  65. /** Default row height in Excel */
  66. #define LXW_DEF_ROW_HEIGHT (double)15.0
  67. /** Gridline options using in `worksheet_gridlines()`. */
  68. enum lxw_gridlines {
  69. /** Hide screen and print gridlines. */
  70. LXW_HIDE_ALL_GRIDLINES = 0,
  71. /** Show screen gridlines. */
  72. LXW_SHOW_SCREEN_GRIDLINES,
  73. /** Show print gridlines. */
  74. LXW_SHOW_PRINT_GRIDLINES,
  75. /** Show screen and print gridlines. */
  76. LXW_SHOW_ALL_GRIDLINES
  77. };
  78. /** Data validation property values. */
  79. enum lxw_validation_boolean {
  80. LXW_VALIDATION_DEFAULT,
  81. /** Turn a data validation property off. */
  82. LXW_VALIDATION_OFF,
  83. /** Turn a data validation property on. Data validation properties are
  84. * generally on by default. */
  85. LXW_VALIDATION_ON
  86. };
  87. /** Data validation types. */
  88. enum lxw_validation_types {
  89. LXW_VALIDATION_TYPE_NONE,
  90. /** Restrict cell input to whole/integer numbers only. */
  91. LXW_VALIDATION_TYPE_INTEGER,
  92. /** Restrict cell input to whole/integer numbers only, using a cell
  93. * reference. */
  94. LXW_VALIDATION_TYPE_INTEGER_FORMULA,
  95. /** Restrict cell input to decimal numbers only. */
  96. LXW_VALIDATION_TYPE_DECIMAL,
  97. /** Restrict cell input to decimal numbers only, using a cell
  98. * reference. */
  99. LXW_VALIDATION_TYPE_DECIMAL_FORMULA,
  100. /** Restrict cell input to a list of strings in a dropdown. */
  101. LXW_VALIDATION_TYPE_LIST,
  102. /** Restrict cell input to a list of strings in a dropdown, using a
  103. * cell range. */
  104. LXW_VALIDATION_TYPE_LIST_FORMULA,
  105. /** Restrict cell input to date values only, using a lxw_datetime type. */
  106. LXW_VALIDATION_TYPE_DATE,
  107. /** Restrict cell input to date values only, using a cell reference. */
  108. LXW_VALIDATION_TYPE_DATE_FORMULA,
  109. /* Restrict cell input to date values only, as a serial number.
  110. * Undocumented. */
  111. LXW_VALIDATION_TYPE_DATE_NUMBER,
  112. /** Restrict cell input to time values only, using a lxw_datetime type. */
  113. LXW_VALIDATION_TYPE_TIME,
  114. /** Restrict cell input to time values only, using a cell reference. */
  115. LXW_VALIDATION_TYPE_TIME_FORMULA,
  116. /* Restrict cell input to time values only, as a serial number.
  117. * Undocumented. */
  118. LXW_VALIDATION_TYPE_TIME_NUMBER,
  119. /** Restrict cell input to strings of defined length, using a cell
  120. * reference. */
  121. LXW_VALIDATION_TYPE_LENGTH,
  122. /** Restrict cell input to strings of defined length, using a cell
  123. * reference. */
  124. LXW_VALIDATION_TYPE_LENGTH_FORMULA,
  125. /** Restrict cell to input controlled by a custom formula that returns
  126. * `TRUE/FALSE`. */
  127. LXW_VALIDATION_TYPE_CUSTOM_FORMULA,
  128. /** Allow any type of input. Mainly only useful for pop-up messages. */
  129. LXW_VALIDATION_TYPE_ANY
  130. };
  131. /** Data validation criteria uses to control the selection of data. */
  132. enum lxw_validation_criteria {
  133. LXW_VALIDATION_CRITERIA_NONE,
  134. /** Select data between two values. */
  135. LXW_VALIDATION_CRITERIA_BETWEEN,
  136. /** Select data that is not between two values. */
  137. LXW_VALIDATION_CRITERIA_NOT_BETWEEN,
  138. /** Select data equal to a value. */
  139. LXW_VALIDATION_CRITERIA_EQUAL_TO,
  140. /** Select data not equal to a value. */
  141. LXW_VALIDATION_CRITERIA_NOT_EQUAL_TO,
  142. /** Select data greater than a value. */
  143. LXW_VALIDATION_CRITERIA_GREATER_THAN,
  144. /** Select data less than a value. */
  145. LXW_VALIDATION_CRITERIA_LESS_THAN,
  146. /** Select data greater than or equal to a value. */
  147. LXW_VALIDATION_CRITERIA_GREATER_THAN_OR_EQUAL_TO,
  148. /** Select data less than or equal to a value. */
  149. LXW_VALIDATION_CRITERIA_LESS_THAN_OR_EQUAL_TO
  150. };
  151. /** Data validation error types for pop-up messages. */
  152. enum lxw_validation_error_types {
  153. /** Show a "Stop" data validation pop-up message. This is the default. */
  154. LXW_VALIDATION_ERROR_TYPE_STOP,
  155. /** Show an "Error" data validation pop-up message. */
  156. LXW_VALIDATION_ERROR_TYPE_WARNING,
  157. /** Show an "Information" data validation pop-up message. */
  158. LXW_VALIDATION_ERROR_TYPE_INFORMATION
  159. };
  160. enum cell_types {
  161. NUMBER_CELL = 1,
  162. STRING_CELL,
  163. INLINE_STRING_CELL,
  164. FORMULA_CELL,
  165. ARRAY_FORMULA_CELL,
  166. BLANK_CELL,
  167. BOOLEAN_CELL,
  168. HYPERLINK_URL,
  169. HYPERLINK_INTERNAL,
  170. HYPERLINK_EXTERNAL
  171. };
  172. enum pane_types {
  173. NO_PANES = 0,
  174. FREEZE_PANES,
  175. SPLIT_PANES,
  176. FREEZE_SPLIT_PANES
  177. };
  178. /* Define the tree.h RB structs for the red-black head types. */
  179. RB_HEAD(lxw_table_cells, lxw_cell);
  180. /* Define a RB_TREE struct manually to add extra members. */
  181. struct lxw_table_rows {
  182. struct lxw_row *rbh_root;
  183. struct lxw_row *cached_row;
  184. lxw_row_t cached_row_num;
  185. };
  186. /* Wrapper around RB_GENERATE_STATIC from tree.h to avoid unused function
  187. * warnings and to avoid portability issues with the _unused attribute. */
  188. #define LXW_RB_GENERATE_ROW(name, type, field, cmp) \
  189. RB_GENERATE_INSERT_COLOR(name, type, field, static) \
  190. RB_GENERATE_REMOVE_COLOR(name, type, field, static) \
  191. RB_GENERATE_INSERT(name, type, field, cmp, static) \
  192. RB_GENERATE_REMOVE(name, type, field, static) \
  193. RB_GENERATE_FIND(name, type, field, cmp, static) \
  194. RB_GENERATE_NEXT(name, type, field, static) \
  195. RB_GENERATE_MINMAX(name, type, field, static) \
  196. /* Add unused struct to allow adding a semicolon */ \
  197. struct lxw_rb_generate_row{int unused;}
  198. #define LXW_RB_GENERATE_CELL(name, type, field, cmp) \
  199. RB_GENERATE_INSERT_COLOR(name, type, field, static) \
  200. RB_GENERATE_REMOVE_COLOR(name, type, field, static) \
  201. RB_GENERATE_INSERT(name, type, field, cmp, static) \
  202. RB_GENERATE_REMOVE(name, type, field, static) \
  203. RB_GENERATE_FIND(name, type, field, cmp, static) \
  204. RB_GENERATE_NEXT(name, type, field, static) \
  205. RB_GENERATE_MINMAX(name, type, field, static) \
  206. /* Add unused struct to allow adding a semicolon */ \
  207. struct lxw_rb_generate_cell{int unused;}
  208. STAILQ_HEAD(lxw_merged_ranges, lxw_merged_range);
  209. STAILQ_HEAD(lxw_selections, lxw_selection);
  210. STAILQ_HEAD(lxw_data_validations, lxw_data_validation);
  211. STAILQ_HEAD(lxw_image_data, lxw_image_options);
  212. STAILQ_HEAD(lxw_chart_data, lxw_image_options);
  213. /**
  214. * @brief Options for rows and columns.
  215. *
  216. * Options struct for the worksheet_set_column() and worksheet_set_row()
  217. * functions.
  218. *
  219. * It has the following members:
  220. *
  221. * * `hidden`
  222. * * `level`
  223. * * `collapsed`
  224. *
  225. * The members of this struct are explained in @ref ww_outlines_grouping.
  226. *
  227. */
  228. typedef struct lxw_row_col_options {
  229. /** Hide the row/column */
  230. uint8_t hidden;
  231. uint8_t level;
  232. uint8_t collapsed;
  233. } lxw_row_col_options;
  234. typedef struct lxw_col_options {
  235. lxw_col_t firstcol;
  236. lxw_col_t lastcol;
  237. double width;
  238. lxw_format *format;
  239. uint8_t hidden;
  240. uint8_t level;
  241. uint8_t collapsed;
  242. } lxw_col_options;
  243. typedef struct lxw_merged_range {
  244. lxw_row_t first_row;
  245. lxw_row_t last_row;
  246. lxw_col_t first_col;
  247. lxw_col_t last_col;
  248. STAILQ_ENTRY (lxw_merged_range) list_pointers;
  249. } lxw_merged_range;
  250. typedef struct lxw_repeat_rows {
  251. uint8_t in_use;
  252. lxw_row_t first_row;
  253. lxw_row_t last_row;
  254. } lxw_repeat_rows;
  255. typedef struct lxw_repeat_cols {
  256. uint8_t in_use;
  257. lxw_col_t first_col;
  258. lxw_col_t last_col;
  259. } lxw_repeat_cols;
  260. typedef struct lxw_print_area {
  261. uint8_t in_use;
  262. lxw_row_t first_row;
  263. lxw_row_t last_row;
  264. lxw_col_t first_col;
  265. lxw_col_t last_col;
  266. } lxw_print_area;
  267. typedef struct lxw_autofilter {
  268. uint8_t in_use;
  269. lxw_row_t first_row;
  270. lxw_row_t last_row;
  271. lxw_col_t first_col;
  272. lxw_col_t last_col;
  273. } lxw_autofilter;
  274. typedef struct lxw_panes {
  275. uint8_t type;
  276. lxw_row_t first_row;
  277. lxw_col_t first_col;
  278. lxw_row_t top_row;
  279. lxw_col_t left_col;
  280. double x_split;
  281. double y_split;
  282. } lxw_panes;
  283. typedef struct lxw_selection {
  284. char pane[LXW_PANE_NAME_LENGTH];
  285. char active_cell[LXW_MAX_CELL_RANGE_LENGTH];
  286. char sqref[LXW_MAX_CELL_RANGE_LENGTH];
  287. STAILQ_ENTRY (lxw_selection) list_pointers;
  288. } lxw_selection;
  289. /**
  290. * @brief Worksheet data validation options.
  291. */
  292. typedef struct lxw_data_validation {
  293. /**
  294. * Set the validation type. Should be a #lxw_validation_types value.
  295. */
  296. uint8_t validate;
  297. /**
  298. * Set the validation criteria type to select the data. Should be a
  299. * #lxw_validation_criteria value.
  300. */
  301. uint8_t criteria;
  302. /** Controls whether a data validation is not applied to blank data in the
  303. * cell. Should be a #lxw_validation_boolean value. It is on by
  304. * default.
  305. */
  306. uint8_t ignore_blank;
  307. /**
  308. * This parameter is used to toggle on and off the 'Show input message
  309. * when cell is selected' option in the Excel data validation dialog. When
  310. * the option is off an input message is not displayed even if it has been
  311. * set using input_message. Should be a #lxw_validation_boolean value. It
  312. * is on by default.
  313. */
  314. uint8_t show_input;
  315. /**
  316. * This parameter is used to toggle on and off the 'Show error alert
  317. * after invalid data is entered' option in the Excel data validation
  318. * dialog. When the option is off an error message is not displayed even
  319. * if it has been set using error_message. Should be a
  320. * #lxw_validation_boolean value. It is on by default.
  321. */
  322. uint8_t show_error;
  323. /**
  324. * This parameter is used to specify the type of error dialog that is
  325. * displayed. Should be a #lxw_validation_error_types value.
  326. */
  327. uint8_t error_type;
  328. /**
  329. * This parameter is used to toggle on and off the 'In-cell dropdown'
  330. * option in the Excel data validation dialog. When the option is on a
  331. * dropdown list will be shown for list validations. Should be a
  332. * #lxw_validation_boolean value. It is on by default.
  333. */
  334. uint8_t dropdown;
  335. uint8_t is_between;
  336. /**
  337. * This parameter is used to set the limiting value to which the criteria
  338. * is applied using a whole or decimal number.
  339. */
  340. double value_number;
  341. /**
  342. * This parameter is used to set the limiting value to which the criteria
  343. * is applied using a cell reference. It is valid for any of the
  344. * `_FORMULA` validation types.
  345. */
  346. char *value_formula;
  347. /**
  348. * This parameter is used to set a list of strings for a drop down list.
  349. * The list should be a `NULL` terminated array of char* strings:
  350. *
  351. * @code
  352. * char *list[] = {"open", "high", "close", NULL};
  353. *
  354. * data_validation->validate = LXW_VALIDATION_TYPE_LIST;
  355. * data_validation->value_list = list;
  356. * @endcode
  357. *
  358. * The `value_formula` parameter can also be used to specify a list from
  359. * an Excel cell range.
  360. *
  361. * Note, the string list is restricted by Excel to 255 characters,
  362. * including comma separators.
  363. */
  364. char **value_list;
  365. /**
  366. * This parameter is used to set the limiting value to which the date or
  367. * time criteria is applied using a #lxw_datetime struct.
  368. */
  369. lxw_datetime value_datetime;
  370. /**
  371. * This parameter is the same as `value_number` but for the minimum value
  372. * when a `BETWEEN` criteria is used.
  373. */
  374. double minimum_number;
  375. /**
  376. * This parameter is the same as `value_formula` but for the minimum value
  377. * when a `BETWEEN` criteria is used.
  378. */
  379. char *minimum_formula;
  380. /**
  381. * This parameter is the same as `value_datetime` but for the minimum value
  382. * when a `BETWEEN` criteria is used.
  383. */
  384. lxw_datetime minimum_datetime;
  385. /**
  386. * This parameter is the same as `value_number` but for the maximum value
  387. * when a `BETWEEN` criteria is used.
  388. */
  389. double maximum_number;
  390. /**
  391. * This parameter is the same as `value_formula` but for the maximum value
  392. * when a `BETWEEN` criteria is used.
  393. */
  394. char *maximum_formula;
  395. /**
  396. * This parameter is the same as `value_datetime` but for the maximum value
  397. * when a `BETWEEN` criteria is used.
  398. */
  399. lxw_datetime maximum_datetime;
  400. /**
  401. * The input_title parameter is used to set the title of the input message
  402. * that is displayed when a cell is entered. It has no default value and
  403. * is only displayed if the input message is displayed. See the
  404. * `input_message` parameter below.
  405. *
  406. * The maximum title length is 32 characters.
  407. */
  408. char *input_title;
  409. /**
  410. * The input_message parameter is used to set the input message that is
  411. * displayed when a cell is entered. It has no default value.
  412. *
  413. * The message can be split over several lines using newlines. The maximum
  414. * message length is 255 characters.
  415. */
  416. char *input_message;
  417. /**
  418. * The error_title parameter is used to set the title of the error message
  419. * that is displayed when the data validation criteria is not met. The
  420. * default error title is 'Microsoft Excel'. The maximum title length is
  421. * 32 characters.
  422. */
  423. char *error_title;
  424. /**
  425. * The error_message parameter is used to set the error message that is
  426. * displayed when a cell is entered. The default error message is "The
  427. * value you entered is not valid. A user has restricted values that can
  428. * be entered into the cell".
  429. *
  430. * The message can be split over several lines using newlines. The maximum
  431. * message length is 255 characters.
  432. */
  433. char *error_message;
  434. char sqref[LXW_MAX_CELL_RANGE_LENGTH];
  435. STAILQ_ENTRY (lxw_data_validation) list_pointers;
  436. } lxw_data_validation;
  437. /**
  438. * @brief Options for inserted images
  439. *
  440. * Options for modifying images inserted via `worksheet_insert_image_opt()`.
  441. *
  442. */
  443. typedef struct lxw_image_options {
  444. /** Offset from the left of the cell in pixels. */
  445. int32_t x_offset;
  446. /** Offset from the top of the cell in pixels. */
  447. int32_t y_offset;
  448. /** X scale of the image as a decimal. */
  449. double x_scale;
  450. /** Y scale of the image as a decimal. */
  451. double y_scale;
  452. lxw_row_t row;
  453. lxw_col_t col;
  454. char *filename;
  455. char *url;
  456. char *tip;
  457. uint8_t anchor;
  458. /* Internal metadata. */
  459. FILE *stream;
  460. uint8_t image_type;
  461. double width;
  462. double height;
  463. char *short_name;
  464. char *extension;
  465. double x_dpi;
  466. double y_dpi;
  467. lxw_chart *chart;
  468. STAILQ_ENTRY (lxw_image_options) list_pointers;
  469. } lxw_image_options;
  470. /**
  471. * @brief Header and footer options.
  472. *
  473. * Optional parameters used in the worksheet_set_header_opt() and
  474. * worksheet_set_footer_opt() functions.
  475. *
  476. */
  477. typedef struct lxw_header_footer_options {
  478. /** Header or footer margin in inches. Excel default is 0.3. */
  479. double margin;
  480. } lxw_header_footer_options;
  481. /**
  482. * @brief Worksheet protection options.
  483. */
  484. typedef struct lxw_protection {
  485. /** Turn off selection of locked cells. This in on in Excel by default.*/
  486. uint8_t no_select_locked_cells;
  487. /** Turn off selection of unlocked cells. This in on in Excel by default.*/
  488. uint8_t no_select_unlocked_cells;
  489. /** Prevent formatting of cells. */
  490. uint8_t format_cells;
  491. /** Prevent formatting of columns. */
  492. uint8_t format_columns;
  493. /** Prevent formatting of rows. */
  494. uint8_t format_rows;
  495. /** Prevent insertion of columns. */
  496. uint8_t insert_columns;
  497. /** Prevent insertion of rows. */
  498. uint8_t insert_rows;
  499. /** Prevent insertion of hyperlinks. */
  500. uint8_t insert_hyperlinks;
  501. /** Prevent deletion of columns. */
  502. uint8_t delete_columns;
  503. /** Prevent deletion of rows. */
  504. uint8_t delete_rows;
  505. /** Prevent sorting data. */
  506. uint8_t sort;
  507. /** Prevent filtering data. */
  508. uint8_t autofilter;
  509. /** Prevent insertion of pivot tables. */
  510. uint8_t pivot_tables;
  511. /** Protect scenarios. */
  512. uint8_t scenarios;
  513. /** Protect drawing objects. */
  514. uint8_t objects;
  515. uint8_t no_sheet;
  516. uint8_t content;
  517. uint8_t is_configured;
  518. char hash[5];
  519. } lxw_protection;
  520. /**
  521. * @brief Struct to represent an Excel worksheet.
  522. *
  523. * The members of the lxw_worksheet struct aren't modified directly. Instead
  524. * the worksheet properties are set by calling the functions shown in
  525. * worksheet.h.
  526. */
  527. typedef struct lxw_worksheet {
  528. FILE *file;
  529. FILE *optimize_tmpfile;
  530. struct lxw_table_rows *table;
  531. struct lxw_table_rows *hyperlinks;
  532. struct lxw_cell **array;
  533. struct lxw_merged_ranges *merged_ranges;
  534. struct lxw_selections *selections;
  535. struct lxw_data_validations *data_validations;
  536. struct lxw_image_data *image_data;
  537. struct lxw_chart_data *chart_data;
  538. lxw_row_t dim_rowmin;
  539. lxw_row_t dim_rowmax;
  540. lxw_col_t dim_colmin;
  541. lxw_col_t dim_colmax;
  542. lxw_sst *sst;
  543. char *name;
  544. char *quoted_name;
  545. char *tmpdir;
  546. uint32_t index;
  547. uint8_t active;
  548. uint8_t selected;
  549. uint8_t hidden;
  550. uint16_t *active_sheet;
  551. uint16_t *first_sheet;
  552. lxw_col_options **col_options;
  553. uint16_t col_options_max;
  554. double *col_sizes;
  555. uint16_t col_sizes_max;
  556. lxw_format **col_formats;
  557. uint16_t col_formats_max;
  558. uint8_t col_size_changed;
  559. uint8_t row_size_changed;
  560. uint8_t optimize;
  561. struct lxw_row *optimize_row;
  562. uint16_t fit_height;
  563. uint16_t fit_width;
  564. uint16_t horizontal_dpi;
  565. uint16_t hlink_count;
  566. uint16_t page_start;
  567. uint16_t print_scale;
  568. uint16_t rel_count;
  569. uint16_t vertical_dpi;
  570. uint16_t zoom;
  571. uint8_t filter_on;
  572. uint8_t fit_page;
  573. uint8_t hcenter;
  574. uint8_t orientation;
  575. uint8_t outline_changed;
  576. uint8_t outline_on;
  577. uint8_t outline_style;
  578. uint8_t outline_below;
  579. uint8_t outline_right;
  580. uint8_t page_order;
  581. uint8_t page_setup_changed;
  582. uint8_t page_view;
  583. uint8_t paper_size;
  584. uint8_t print_gridlines;
  585. uint8_t print_headers;
  586. uint8_t print_options_changed;
  587. uint8_t right_to_left;
  588. uint8_t screen_gridlines;
  589. uint8_t show_zeros;
  590. uint8_t vba_codename;
  591. uint8_t vcenter;
  592. uint8_t zoom_scale_normal;
  593. uint8_t num_validations;
  594. lxw_color_t tab_color;
  595. double margin_left;
  596. double margin_right;
  597. double margin_top;
  598. double margin_bottom;
  599. double margin_header;
  600. double margin_footer;
  601. double default_row_height;
  602. uint32_t default_row_pixels;
  603. uint32_t default_col_pixels;
  604. uint8_t default_row_zeroed;
  605. uint8_t default_row_set;
  606. uint8_t outline_row_level;
  607. uint8_t outline_col_level;
  608. uint8_t header_footer_changed;
  609. char header[LXW_HEADER_FOOTER_MAX];
  610. char footer[LXW_HEADER_FOOTER_MAX];
  611. struct lxw_repeat_rows repeat_rows;
  612. struct lxw_repeat_cols repeat_cols;
  613. struct lxw_print_area print_area;
  614. struct lxw_autofilter autofilter;
  615. uint16_t merged_range_count;
  616. lxw_row_t *hbreaks;
  617. lxw_col_t *vbreaks;
  618. uint16_t hbreaks_count;
  619. uint16_t vbreaks_count;
  620. struct lxw_rel_tuples *external_hyperlinks;
  621. struct lxw_rel_tuples *external_drawing_links;
  622. struct lxw_rel_tuples *drawing_links;
  623. struct lxw_panes panes;
  624. struct lxw_protection protection;
  625. lxw_drawing *drawing;
  626. STAILQ_ENTRY (lxw_worksheet) list_pointers;
  627. } lxw_worksheet;
  628. /*
  629. * Worksheet initialization data.
  630. */
  631. typedef struct lxw_worksheet_init_data {
  632. uint32_t index;
  633. uint8_t hidden;
  634. uint8_t optimize;
  635. uint16_t *active_sheet;
  636. uint16_t *first_sheet;
  637. lxw_sst *sst;
  638. char *name;
  639. char *quoted_name;
  640. char *tmpdir;
  641. } lxw_worksheet_init_data;
  642. /* Struct to represent a worksheet row. */
  643. typedef struct lxw_row {
  644. lxw_row_t row_num;
  645. double height;
  646. lxw_format *format;
  647. uint8_t hidden;
  648. uint8_t level;
  649. uint8_t collapsed;
  650. uint8_t row_changed;
  651. uint8_t data_changed;
  652. uint8_t height_changed;
  653. struct lxw_table_cells *cells;
  654. /* tree management pointers for tree.h. */
  655. RB_ENTRY (lxw_row) tree_pointers;
  656. } lxw_row;
  657. /* Struct to represent a worksheet cell. */
  658. typedef struct lxw_cell {
  659. lxw_row_t row_num;
  660. lxw_col_t col_num;
  661. enum cell_types type;
  662. lxw_format *format;
  663. union {
  664. double number;
  665. int32_t string_id;
  666. char *string;
  667. } u;
  668. double formula_result;
  669. char *user_data1;
  670. char *user_data2;
  671. char *sst_string;
  672. /* List pointers for tree.h. */
  673. RB_ENTRY (lxw_cell) tree_pointers;
  674. } lxw_cell;
  675. /* *INDENT-OFF* */
  676. #ifdef __cplusplus
  677. extern "C" {
  678. #endif
  679. /* *INDENT-ON* */
  680. /**
  681. * @brief Write a number to a worksheet cell.
  682. *
  683. * @param worksheet pointer to a lxw_worksheet instance to be updated.
  684. * @param row The zero indexed row number.
  685. * @param col The zero indexed column number.
  686. * @param number The number to write to the cell.
  687. * @param format A pointer to a Format instance or NULL.
  688. *
  689. * @return A #lxw_error code.
  690. *
  691. * The `worksheet_write_number()` function writes numeric types to the cell
  692. * specified by `row` and `column`:
  693. *
  694. * @code
  695. * worksheet_write_number(worksheet, 0, 0, 123456, NULL);
  696. * worksheet_write_number(worksheet, 1, 0, 2.3451, NULL);
  697. * @endcode
  698. *
  699. * @image html write_number01.png
  700. *
  701. * The native data type for all numbers in Excel is a IEEE-754 64-bit
  702. * double-precision floating point, which is also the default type used by
  703. * `%worksheet_write_number`.
  704. *
  705. * The `format` parameter is used to apply formatting to the cell. This
  706. * parameter can be `NULL` to indicate no formatting or it can be a
  707. * @ref format.h "Format" object.
  708. *
  709. * @code
  710. * lxw_format *format = workbook_add_format(workbook);
  711. * format_set_num_format(format, "$#,##0.00");
  712. *
  713. * worksheet_write_number(worksheet, 0, 0, 1234.567, format);
  714. * @endcode
  715. *
  716. * @image html write_number02.png
  717. *
  718. * @note Excel doesn't support `NaN`, `Inf` or `-Inf` as a number value. If
  719. * you are writing data that contains these values then your application
  720. * should convert them to a string or handle them in some other way.
  721. *
  722. */
  723. lxw_error worksheet_write_number(lxw_worksheet *worksheet,
  724. lxw_row_t row,
  725. lxw_col_t col, double number,
  726. lxw_format *format);
  727. /**
  728. * @brief Write a string to a worksheet cell.
  729. *
  730. * @param worksheet pointer to a lxw_worksheet instance to be updated.
  731. * @param row The zero indexed row number.
  732. * @param col The zero indexed column number.
  733. * @param string String to write to cell.
  734. * @param format A pointer to a Format instance or NULL.
  735. *
  736. * @return A #lxw_error code.
  737. *
  738. * The `%worksheet_write_string()` function writes a string to the cell
  739. * specified by `row` and `column`:
  740. *
  741. * @code
  742. * worksheet_write_string(worksheet, 0, 0, "This phrase is English!", NULL);
  743. * @endcode
  744. *
  745. * @image html write_string01.png
  746. *
  747. * The `format` parameter is used to apply formatting to the cell. This
  748. * parameter can be `NULL` to indicate no formatting or it can be a
  749. * @ref format.h "Format" object:
  750. *
  751. * @code
  752. * lxw_format *format = workbook_add_format(workbook);
  753. * format_set_bold(format);
  754. *
  755. * worksheet_write_string(worksheet, 0, 0, "This phrase is Bold!", format);
  756. * @endcode
  757. *
  758. * @image html write_string02.png
  759. *
  760. * Unicode strings are supported in UTF-8 encoding. This generally requires
  761. * that your source file is UTF-8 encoded or that the data has been read from
  762. * a UTF-8 source:
  763. *
  764. * @code
  765. * worksheet_write_string(worksheet, 0, 0, "Это фраза на русском!", NULL);
  766. * @endcode
  767. *
  768. * @image html write_string03.png
  769. *
  770. */
  771. lxw_error worksheet_write_string(lxw_worksheet *worksheet,
  772. lxw_row_t row,
  773. lxw_col_t col, const char *string,
  774. lxw_format *format);
  775. /**
  776. * @brief Write a formula to a worksheet cell.
  777. *
  778. * @param worksheet pointer to a lxw_worksheet instance to be updated.
  779. * @param row The zero indexed row number.
  780. * @param col The zero indexed column number.
  781. * @param formula Formula string to write to cell.
  782. * @param format A pointer to a Format instance or NULL.
  783. *
  784. * @return A #lxw_error code.
  785. *
  786. * The `%worksheet_write_formula()` function writes a formula or function to
  787. * the cell specified by `row` and `column`:
  788. *
  789. * @code
  790. * worksheet_write_formula(worksheet, 0, 0, "=B3 + 6", NULL);
  791. * worksheet_write_formula(worksheet, 1, 0, "=SIN(PI()/4)", NULL);
  792. * worksheet_write_formula(worksheet, 2, 0, "=SUM(A1:A2)", NULL);
  793. * worksheet_write_formula(worksheet, 3, 0, "=IF(A3>1,\"Yes\", \"No\")", NULL);
  794. * worksheet_write_formula(worksheet, 4, 0, "=AVERAGE(1, 2, 3, 4)", NULL);
  795. * worksheet_write_formula(worksheet, 5, 0, "=DATEVALUE(\"1-Jan-2013\")", NULL);
  796. * @endcode
  797. *
  798. * @image html write_formula01.png
  799. *
  800. * The `format` parameter is used to apply formatting to the cell. This
  801. * parameter can be `NULL` to indicate no formatting or it can be a
  802. * @ref format.h "Format" object.
  803. *
  804. * Libxlsxwriter doesn't calculate the value of a formula and instead stores a
  805. * default value of `0`. The correct formula result is displayed in Excel, as
  806. * shown in the example above, since it recalculates the formulas when it loads
  807. * the file. For cases where this is an issue see the
  808. * `worksheet_write_formula_num()` function and the discussion in that section.
  809. *
  810. * Formulas must be written with the US style separator/range operator which
  811. * is a comma (not semi-colon). Therefore a formula with multiple values
  812. * should be written as follows:
  813. *
  814. * @code
  815. * // OK.
  816. * worksheet_write_formula(worksheet, 0, 0, "=SUM(1, 2, 3)", NULL);
  817. *
  818. * // NO. Error on load.
  819. * worksheet_write_formula(worksheet, 1, 0, "=SUM(1; 2; 3)", NULL);
  820. * @endcode
  821. *
  822. * See also @ref working_with_formulas.
  823. */
  824. lxw_error worksheet_write_formula(lxw_worksheet *worksheet,
  825. lxw_row_t row,
  826. lxw_col_t col, const char *formula,
  827. lxw_format *format);
  828. /**
  829. * @brief Write an array formula to a worksheet cell.
  830. *
  831. * @param worksheet pointer to a lxw_worksheet instance to be updated.
  832. * @param first_row The first row of the range. (All zero indexed.)
  833. * @param first_col The first column of the range.
  834. * @param last_row The last row of the range.
  835. * @param last_col The last col of the range.
  836. * @param formula Array formula to write to cell.
  837. * @param format A pointer to a Format instance or NULL.
  838. *
  839. * @return A #lxw_error code.
  840. *
  841. * The `%worksheet_write_array_formula()` function writes an array formula to
  842. * a cell range. In Excel an array formula is a formula that performs a
  843. * calculation on a set of values.
  844. *
  845. * In Excel an array formula is indicated by a pair of braces around the
  846. * formula: `{=SUM(A1:B1*A2:B2)}`.
  847. *
  848. * Array formulas can return a single value or a range or values. For array
  849. * formulas that return a range of values you must specify the range that the
  850. * return values will be written to. This is why this function has `first_`
  851. * and `last_` row/column parameters. The RANGE() macro can also be used to
  852. * specify the range:
  853. *
  854. * @code
  855. * worksheet_write_array_formula(worksheet, 4, 0, 6, 0, "{=TREND(C5:C7,B5:B7)}", NULL);
  856. *
  857. * // Same as above using the RANGE() macro.
  858. * worksheet_write_array_formula(worksheet, RANGE("A5:A7"), "{=TREND(C5:C7,B5:B7)}", NULL);
  859. * @endcode
  860. *
  861. * If the array formula returns a single value then the `first_` and `last_`
  862. * parameters should be the same:
  863. *
  864. * @code
  865. * worksheet_write_array_formula(worksheet, 1, 0, 1, 0, "{=SUM(B1:C1*B2:C2)}", NULL);
  866. * worksheet_write_array_formula(worksheet, RANGE("A2:A2"), "{=SUM(B1:C1*B2:C2)}", NULL);
  867. * @endcode
  868. *
  869. */
  870. lxw_error worksheet_write_array_formula(lxw_worksheet *worksheet,
  871. lxw_row_t first_row,
  872. lxw_col_t first_col,
  873. lxw_row_t last_row,
  874. lxw_col_t last_col,
  875. const char *formula,
  876. lxw_format *format);
  877. lxw_error worksheet_write_array_formula_num(lxw_worksheet *worksheet,
  878. lxw_row_t first_row,
  879. lxw_col_t first_col,
  880. lxw_row_t last_row,
  881. lxw_col_t last_col,
  882. const char *formula,
  883. lxw_format *format,
  884. double result);
  885. /**
  886. * @brief Write a date or time to a worksheet cell.
  887. *
  888. * @param worksheet pointer to a lxw_worksheet instance to be updated.
  889. * @param row The zero indexed row number.
  890. * @param col The zero indexed column number.
  891. * @param datetime The datetime to write to the cell.
  892. * @param format A pointer to a Format instance or NULL.
  893. *
  894. * @return A #lxw_error code.
  895. *
  896. * The `worksheet_write_datetime()` function can be used to write a date or
  897. * time to the cell specified by `row` and `column`:
  898. *
  899. * @dontinclude dates_and_times02.c
  900. * @skip include
  901. * @until num_format
  902. * @skip Feb
  903. * @until }
  904. *
  905. * The `format` parameter should be used to apply formatting to the cell using
  906. * a @ref format.h "Format" object as shown above. Without a date format the
  907. * datetime will appear as a number only.
  908. *
  909. * See @ref working_with_dates for more information about handling dates and
  910. * times in libxlsxwriter.
  911. */
  912. lxw_error worksheet_write_datetime(lxw_worksheet *worksheet,
  913. lxw_row_t row,
  914. lxw_col_t col, lxw_datetime *datetime,
  915. lxw_format *format);
  916. lxw_error worksheet_write_url_opt(lxw_worksheet *worksheet,
  917. lxw_row_t row_num,
  918. lxw_col_t col_num, const char *url,
  919. lxw_format *format, const char *string,
  920. const char *tooltip);
  921. /**
  922. *
  923. * @param worksheet pointer to a lxw_worksheet instance to be updated.
  924. * @param row The zero indexed row number.
  925. * @param col The zero indexed column number.
  926. * @param url The url to write to the cell.
  927. * @param format A pointer to a Format instance or NULL.
  928. *
  929. * @return A #lxw_error code.
  930. *
  931. *
  932. * The `%worksheet_write_url()` function is used to write a URL/hyperlink to a
  933. * worksheet cell specified by `row` and `column`.
  934. *
  935. * @code
  936. * worksheet_write_url(worksheet, 0, 0, "http://libxlsxwriter.github.io", url_format);
  937. * @endcode
  938. *
  939. * @image html hyperlinks_short.png
  940. *
  941. * The `format` parameter is used to apply formatting to the cell. This
  942. * parameter can be `NULL` to indicate no formatting or it can be a @ref
  943. * format.h "Format" object. The typical worksheet format for a hyperlink is a
  944. * blue underline:
  945. *
  946. * @code
  947. * lxw_format *url_format = workbook_add_format(workbook);
  948. *
  949. * format_set_underline (url_format, LXW_UNDERLINE_SINGLE);
  950. * format_set_font_color(url_format, LXW_COLOR_BLUE);
  951. *
  952. * @endcode
  953. *
  954. * The usual web style URI's are supported: `%http://`, `%https://`, `%ftp://`
  955. * and `mailto:` :
  956. *
  957. * @code
  958. * worksheet_write_url(worksheet, 0, 0, "ftp://www.python.org/", url_format);
  959. * worksheet_write_url(worksheet, 1, 0, "http://www.python.org/", url_format);
  960. * worksheet_write_url(worksheet, 2, 0, "https://www.python.org/", url_format);
  961. * worksheet_write_url(worksheet, 3, 0, "mailto:[email protected]", url_format);
  962. *
  963. * @endcode
  964. *
  965. * An Excel hyperlink is comprised of two elements: the displayed string and
  966. * the non-displayed link. By default the displayed string is the same as the
  967. * link. However, it is possible to overwrite it with any other
  968. * `libxlsxwriter` type using the appropriate `worksheet_write_*()`
  969. * function. The most common case is to overwrite the displayed link text with
  970. * another string:
  971. *
  972. * @code
  973. * // Write a hyperlink but overwrite the displayed string.
  974. * worksheet_write_url (worksheet, 2, 0, "http://libxlsxwriter.github.io", url_format);
  975. * worksheet_write_string(worksheet, 2, 0, "Read the documentation.", url_format);
  976. *
  977. * @endcode
  978. *
  979. * @image html hyperlinks_short2.png
  980. *
  981. * Two local URIs are supported: `internal:` and `external:`. These are used
  982. * for hyperlinks to internal worksheet references or external workbook and
  983. * worksheet references:
  984. *
  985. * @code
  986. * worksheet_write_url(worksheet, 0, 0, "internal:Sheet2!A1", url_format);
  987. * worksheet_write_url(worksheet, 1, 0, "internal:Sheet2!B2", url_format);
  988. * worksheet_write_url(worksheet, 2, 0, "internal:Sheet2!A1:B2", url_format);
  989. * worksheet_write_url(worksheet, 3, 0, "internal:'Sales Data'!A1", url_format);
  990. * worksheet_write_url(worksheet, 4, 0, "external:c:\\temp\\foo.xlsx", url_format);
  991. * worksheet_write_url(worksheet, 5, 0, "external:c:\\foo.xlsx#Sheet2!A1", url_format);
  992. * worksheet_write_url(worksheet, 6, 0, "external:..\\foo.xlsx", url_format);
  993. * worksheet_write_url(worksheet, 7, 0, "external:..\\foo.xlsx#Sheet2!A1", url_format);
  994. * worksheet_write_url(worksheet, 8, 0, "external:\\\\NET\\share\\foo.xlsx", url_format);
  995. *
  996. * @endcode
  997. *
  998. * Worksheet references are typically of the form `Sheet1!A1`. You can also
  999. * link to a worksheet range using the standard Excel notation:
  1000. * `Sheet1!A1:B2`.
  1001. *
  1002. * In external links the workbook and worksheet name must be separated by the
  1003. * `#` character:
  1004. *
  1005. * @code
  1006. * worksheet_write_url(worksheet, 0, 0, "external:c:\\foo.xlsx#Sheet2!A1", url_format);
  1007. * @endcode
  1008. *
  1009. * You can also link to a named range in the target worksheet: For example say
  1010. * you have a named range called `my_name` in the workbook `c:\temp\foo.xlsx`
  1011. * you could link to it as follows:
  1012. *
  1013. * @code
  1014. * worksheet_write_url(worksheet, 0, 0, "external:c:\\temp\\foo.xlsx#my_name", url_format);
  1015. *
  1016. * @endcode
  1017. *
  1018. * Excel requires that worksheet names containing spaces or non alphanumeric
  1019. * characters are single quoted as follows:
  1020. *
  1021. * @code
  1022. * worksheet_write_url(worksheet, 0, 0, "internal:'Sales Data'!A1", url_format);
  1023. * @endcode
  1024. *
  1025. * Links to network files are also supported. Network files normally begin
  1026. * with two back slashes as follows `\\NETWORK\etc`. In order to represent
  1027. * this in a C string literal the backslashes should be escaped:
  1028. * @code
  1029. * worksheet_write_url(worksheet, 0, 0, "external:\\\\NET\\share\\foo.xlsx", url_format);
  1030. * @endcode
  1031. *
  1032. *
  1033. * Alternatively, you can use Unix style forward slashes. These are
  1034. * translated internally to backslashes:
  1035. *
  1036. * @code
  1037. * worksheet_write_url(worksheet, 0, 0, "external:c:/temp/foo.xlsx", url_format);
  1038. * worksheet_write_url(worksheet, 1, 0, "external://NET/share/foo.xlsx", url_format);
  1039. *
  1040. * @endcode
  1041. *
  1042. *
  1043. * **Note:**
  1044. *
  1045. * libxlsxwriter will escape the following characters in URLs as required
  1046. * by Excel: `\s " < > \ [ ] ^ { }` unless the URL already contains `%%xx`
  1047. * style escapes. In which case it is assumed that the URL was escaped
  1048. * correctly by the user and will by passed directly to Excel.
  1049. *
  1050. */
  1051. lxw_error worksheet_write_url(lxw_worksheet *worksheet,
  1052. lxw_row_t row,
  1053. lxw_col_t col, const char *url,
  1054. lxw_format *format);
  1055. /**
  1056. * @brief Write a formatted boolean worksheet cell.
  1057. *
  1058. * @param worksheet pointer to a lxw_worksheet instance to be updated.
  1059. * @param row The zero indexed row number.
  1060. * @param col The zero indexed column number.
  1061. * @param value The boolean value to write to the cell.
  1062. * @param format A pointer to a Format instance or NULL.
  1063. *
  1064. * @return A #lxw_error code.
  1065. *
  1066. * Write an Excel boolean to the cell specified by `row` and `column`:
  1067. *
  1068. * @code
  1069. * worksheet_write_boolean(worksheet, 2, 2, 0, my_format);
  1070. * @endcode
  1071. *
  1072. */
  1073. lxw_error worksheet_write_boolean(lxw_worksheet *worksheet,
  1074. lxw_row_t row, lxw_col_t col,
  1075. int value, lxw_format *format);
  1076. /**
  1077. * @brief Write a formatted blank worksheet cell.
  1078. *
  1079. * @param worksheet pointer to a lxw_worksheet instance to be updated.
  1080. * @param row The zero indexed row number.
  1081. * @param col The zero indexed column number.
  1082. * @param format A pointer to a Format instance or NULL.
  1083. *
  1084. * @return A #lxw_error code.
  1085. *
  1086. * Write a blank cell specified by `row` and `column`:
  1087. *
  1088. * @code
  1089. * worksheet_write_blank(worksheet, 1, 1, border_format);
  1090. * @endcode
  1091. *
  1092. * This function is used to add formatting to a cell which doesn't contain a
  1093. * string or number value.
  1094. *
  1095. * Excel differentiates between an "Empty" cell and a "Blank" cell. An Empty
  1096. * cell is a cell which doesn't contain data or formatting whilst a Blank cell
  1097. * doesn't contain data but does contain formatting. Excel stores Blank cells
  1098. * but ignores Empty cells.
  1099. *
  1100. * As such, if you write an empty cell without formatting it is ignored.
  1101. *
  1102. */
  1103. lxw_error worksheet_write_blank(lxw_worksheet *worksheet,
  1104. lxw_row_t row, lxw_col_t col,
  1105. lxw_format *format);
  1106. /**
  1107. * @brief Write a formula to a worksheet cell with a user defined result.
  1108. *
  1109. * @param worksheet pointer to a lxw_worksheet instance to be updated.
  1110. * @param row The zero indexed row number.
  1111. * @param col The zero indexed column number.
  1112. * @param formula Formula string to write to cell.
  1113. * @param format A pointer to a Format instance or NULL.
  1114. * @param result A user defined result for a formula.
  1115. *
  1116. * @return A #lxw_error code.
  1117. *
  1118. * The `%worksheet_write_formula_num()` function writes a formula or Excel
  1119. * function to the cell specified by `row` and `column` with a user defined
  1120. * result:
  1121. *
  1122. * @code
  1123. * // Required as a workaround only.
  1124. * worksheet_write_formula_num(worksheet, 0, 0, "=1 + 2", NULL, 3);
  1125. * @endcode
  1126. *
  1127. * Libxlsxwriter doesn't calculate the value of a formula and instead stores
  1128. * the value `0` as the formula result. It then sets a global flag in the XLSX
  1129. * file to say that all formulas and functions should be recalculated when the
  1130. * file is opened.
  1131. *
  1132. * This is the method recommended in the Excel documentation and in general it
  1133. * works fine with spreadsheet applications.
  1134. *
  1135. * However, applications that don't have a facility to calculate formulas,
  1136. * such as Excel Viewer, or some mobile applications will only display the `0`
  1137. * results.
  1138. *
  1139. * If required, the `%worksheet_write_formula_num()` function can be used to
  1140. * specify a formula and its result.
  1141. *
  1142. * This function is rarely required and is only provided for compatibility
  1143. * with some third party applications. For most applications the
  1144. * worksheet_write_formula() function is the recommended way of writing
  1145. * formulas.
  1146. *
  1147. * See also @ref working_with_formulas.
  1148. */
  1149. lxw_error worksheet_write_formula_num(lxw_worksheet *worksheet,
  1150. lxw_row_t row,
  1151. lxw_col_t col,
  1152. const char *formula,
  1153. lxw_format *format, double result);
  1154. /**
  1155. * @brief Set the properties for a row of cells.
  1156. *
  1157. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1158. * @param row The zero indexed row number.
  1159. * @param height The row height.
  1160. * @param format A pointer to a Format instance or NULL.
  1161. *
  1162. * The `%worksheet_set_row()` function is used to change the default
  1163. * properties of a row. The most common use for this function is to change the
  1164. * height of a row:
  1165. *
  1166. * @code
  1167. * // Set the height of Row 1 to 20.
  1168. * worksheet_set_row(worksheet, 0, 20, NULL);
  1169. * @endcode
  1170. *
  1171. * The other common use for `%worksheet_set_row()` is to set the a @ref
  1172. * format.h "Format" for all cells in the row:
  1173. *
  1174. * @code
  1175. * lxw_format *bold = workbook_add_format(workbook);
  1176. * format_set_bold(bold);
  1177. *
  1178. * // Set the header row to bold.
  1179. * worksheet_set_row(worksheet, 0, 15, bold);
  1180. * @endcode
  1181. *
  1182. * If you wish to set the format of a row without changing the height you can
  1183. * pass the default row height of #LXW_DEF_ROW_HEIGHT = 15:
  1184. *
  1185. * @code
  1186. * worksheet_set_row(worksheet, 0, LXW_DEF_ROW_HEIGHT, format);
  1187. * worksheet_set_row(worksheet, 0, 15, format); // Same as above.
  1188. * @endcode
  1189. *
  1190. * The `format` parameter will be applied to any cells in the row that don't
  1191. * have a format. As with Excel the row format is overridden by an explicit
  1192. * cell format. For example:
  1193. *
  1194. * @code
  1195. * // Row 1 has format1.
  1196. * worksheet_set_row(worksheet, 0, 15, format1);
  1197. *
  1198. * // Cell A1 in Row 1 defaults to format1.
  1199. * worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
  1200. *
  1201. * // Cell B1 in Row 1 keeps format2.
  1202. * worksheet_write_string(worksheet, 0, 1, "Hello", format2);
  1203. * @endcode
  1204. *
  1205. */
  1206. lxw_error worksheet_set_row(lxw_worksheet *worksheet,
  1207. lxw_row_t row, double height, lxw_format *format);
  1208. /**
  1209. * @brief Set the properties for a row of cells.
  1210. *
  1211. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1212. * @param row The zero indexed row number.
  1213. * @param height The row height.
  1214. * @param format A pointer to a Format instance or NULL.
  1215. * @param options Optional row parameters: hidden, level, collapsed.
  1216. *
  1217. * The `%worksheet_set_row_opt()` function is the same as
  1218. * `worksheet_set_row()` with an additional `options` parameter.
  1219. *
  1220. * The `options` parameter is a #lxw_row_col_options struct. It has the
  1221. * following members:
  1222. *
  1223. * - `hidden`
  1224. * - `level`
  1225. * - `collapsed`
  1226. *
  1227. * The `"hidden"` option is used to hide a row. This can be used, for
  1228. * example, to hide intermediary steps in a complicated calculation:
  1229. *
  1230. * @code
  1231. * lxw_row_col_options options1 = {.hidden = 1, .level = 0, .collapsed = 0};
  1232. *
  1233. * // Hide the fourth and fifth (zero indexed) rows.
  1234. * worksheet_set_row_opt(worksheet, 3, LXW_DEF_ROW_HEIGHT, NULL, &options1);
  1235. * worksheet_set_row_opt(worksheet, 4, LXW_DEF_ROW_HEIGHT, NULL, &options1);
  1236. *
  1237. * @endcode
  1238. *
  1239. * @image html hide_row_col2.png
  1240. *
  1241. * The `"hidden"`, `"level"`, and `"collapsed"`, options can also be used to
  1242. * create Outlines and Grouping. See @ref working_with_outlines.
  1243. *
  1244. * @code
  1245. * // The option structs with the outline level set.
  1246. * lxw_row_col_options options1 = {.hidden = 0, .level = 2, .collapsed = 0};
  1247. * lxw_row_col_options options2 = {.hidden = 0, .level = 1, .collapsed = 0};
  1248. *
  1249. *
  1250. * // Set the row options with the outline level.
  1251. * worksheet_set_row_opt(worksheet, 1, LXW_DEF_ROW_HEIGHT, NULL, &options1);
  1252. * worksheet_set_row_opt(worksheet, 2, LXW_DEF_ROW_HEIGHT, NULL, &options1);
  1253. * worksheet_set_row_opt(worksheet, 3, LXW_DEF_ROW_HEIGHT, NULL, &options1);
  1254. * worksheet_set_row_opt(worksheet, 4, LXW_DEF_ROW_HEIGHT, NULL, &options1);
  1255. * worksheet_set_row_opt(worksheet, 5, LXW_DEF_ROW_HEIGHT, NULL, &options2);
  1256. *
  1257. * worksheet_set_row_opt(worksheet, 6, LXW_DEF_ROW_HEIGHT, NULL, &options1);
  1258. * worksheet_set_row_opt(worksheet, 7, LXW_DEF_ROW_HEIGHT, NULL, &options1);
  1259. * worksheet_set_row_opt(worksheet, 8, LXW_DEF_ROW_HEIGHT, NULL, &options1);
  1260. * worksheet_set_row_opt(worksheet, 9, LXW_DEF_ROW_HEIGHT, NULL, &options1);
  1261. * worksheet_set_row_opt(worksheet, 10, LXW_DEF_ROW_HEIGHT, NULL, &options2);
  1262. * @endcode
  1263. *
  1264. * @image html outline1.png
  1265. *
  1266. */
  1267. lxw_error worksheet_set_row_opt(lxw_worksheet *worksheet,
  1268. lxw_row_t row,
  1269. double height,
  1270. lxw_format *format,
  1271. lxw_row_col_options *options);
  1272. /**
  1273. * @brief Set the properties for one or more columns of cells.
  1274. *
  1275. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1276. * @param first_col The zero indexed first column.
  1277. * @param last_col The zero indexed last column.
  1278. * @param width The width of the column(s).
  1279. * @param format A pointer to a Format instance or NULL.
  1280. *
  1281. * The `%worksheet_set_column()` function can be used to change the default
  1282. * properties of a single column or a range of columns:
  1283. *
  1284. * @code
  1285. * // Width of columns B:D set to 30.
  1286. * worksheet_set_column(worksheet, 1, 3, 30, NULL);
  1287. *
  1288. * @endcode
  1289. *
  1290. * If `%worksheet_set_column()` is applied to a single column the value of
  1291. * `first_col` and `last_col` should be the same:
  1292. *
  1293. * @code
  1294. * // Width of column B set to 30.
  1295. * worksheet_set_column(worksheet, 1, 1, 30, NULL);
  1296. *
  1297. * @endcode
  1298. *
  1299. * It is also possible, and generally clearer, to specify a column range using
  1300. * the form of `COLS()` macro:
  1301. *
  1302. * @code
  1303. * worksheet_set_column(worksheet, 4, 4, 20, NULL);
  1304. * worksheet_set_column(worksheet, 5, 8, 30, NULL);
  1305. *
  1306. * // Same as the examples above but clearer.
  1307. * worksheet_set_column(worksheet, COLS("E:E"), 20, NULL);
  1308. * worksheet_set_column(worksheet, COLS("F:H"), 30, NULL);
  1309. *
  1310. * @endcode
  1311. *
  1312. * The `width` parameter sets the column width in the same units used by Excel
  1313. * which is: the number of characters in the default font. The default width
  1314. * is 8.43 in the default font of Calibri 11. The actual relationship between
  1315. * a string width and a column width in Excel is complex. See the
  1316. * [following explanation of column widths](https://support.microsoft.com/en-us/kb/214123)
  1317. * from the Microsoft support documentation for more details.
  1318. *
  1319. * There is no way to specify "AutoFit" for a column in the Excel file
  1320. * format. This feature is only available at runtime from within Excel. It is
  1321. * possible to simulate "AutoFit" in your application by tracking the maximum
  1322. * width of the data in the column as your write it and then adjusting the
  1323. * column width at the end.
  1324. *
  1325. * As usual the @ref format.h `format` parameter is optional. If you wish to
  1326. * set the format without changing the width you can pass a default column
  1327. * width of #LXW_DEF_COL_WIDTH = 8.43:
  1328. *
  1329. * @code
  1330. * lxw_format *bold = workbook_add_format(workbook);
  1331. * format_set_bold(bold);
  1332. *
  1333. * // Set the first column to bold.
  1334. * worksheet_set_column(worksheet, 0, 0, LXW_DEF_COL_HEIGHT, bold);
  1335. * @endcode
  1336. *
  1337. * The `format` parameter will be applied to any cells in the column that
  1338. * don't have a format. For example:
  1339. *
  1340. * @code
  1341. * // Column 1 has format1.
  1342. * worksheet_set_column(worksheet, COLS("A:A"), 8.43, format1);
  1343. *
  1344. * // Cell A1 in column 1 defaults to format1.
  1345. * worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
  1346. *
  1347. * // Cell A2 in column 1 keeps format2.
  1348. * worksheet_write_string(worksheet, 1, 0, "Hello", format2);
  1349. * @endcode
  1350. *
  1351. * As in Excel a row format takes precedence over a default column format:
  1352. *
  1353. * @code
  1354. * // Row 1 has format1.
  1355. * worksheet_set_row(worksheet, 0, 15, format1);
  1356. *
  1357. * // Col 1 has format2.
  1358. * worksheet_set_column(worksheet, COLS("A:A"), 8.43, format2);
  1359. *
  1360. * // Cell A1 defaults to format1, the row format.
  1361. * worksheet_write_string(worksheet, 0, 0, "Hello", NULL);
  1362. *
  1363. * // Cell A2 keeps format2, the column format.
  1364. * worksheet_write_string(worksheet, 1, 0, "Hello", NULL);
  1365. * @endcode
  1366. */
  1367. lxw_error worksheet_set_column(lxw_worksheet *worksheet,
  1368. lxw_col_t first_col,
  1369. lxw_col_t last_col,
  1370. double width, lxw_format *format);
  1371. /**
  1372. * @brief Set the properties for one or more columns of cells with options.
  1373. *
  1374. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1375. * @param first_col The zero indexed first column.
  1376. * @param last_col The zero indexed last column.
  1377. * @param width The width of the column(s).
  1378. * @param format A pointer to a Format instance or NULL.
  1379. * @param options Optional row parameters: hidden, level, collapsed.
  1380. *
  1381. * The `%worksheet_set_column_opt()` function is the same as
  1382. * `worksheet_set_column()` with an additional `options` parameter.
  1383. *
  1384. * The `options` parameter is a #lxw_row_col_options struct. It has the
  1385. * following members:
  1386. *
  1387. * - `hidden`
  1388. * - `level`
  1389. * - `collapsed`
  1390. *
  1391. * The `"hidden"` option is used to hide a column. This can be used, for
  1392. * example, to hide intermediary steps in a complicated calculation:
  1393. *
  1394. * @code
  1395. * lxw_row_col_options options1 = {.hidden = 1, .level = 0, .collapsed = 0};
  1396. *
  1397. * worksheet_set_column_opt(worksheet, COLS("D:E"), LXW_DEF_COL_WIDTH, NULL, &options1);
  1398. * @endcode
  1399. *
  1400. * @image html hide_row_col3.png
  1401. *
  1402. * The `"hidden"`, `"level"`, and `"collapsed"`, options can also be used to
  1403. * create Outlines and Grouping. See @ref working_with_outlines.
  1404. *
  1405. * @code
  1406. * lxw_row_col_options options1 = {.hidden = 0, .level = 1, .collapsed = 0};
  1407. *
  1408. * worksheet_set_column_opt(worksheet, COLS("B:G"), 5, NULL, &options1);
  1409. * @endcode
  1410. *
  1411. * @image html outline8.png
  1412. */
  1413. lxw_error worksheet_set_column_opt(lxw_worksheet *worksheet,
  1414. lxw_col_t first_col,
  1415. lxw_col_t last_col,
  1416. double width,
  1417. lxw_format *format,
  1418. lxw_row_col_options *options);
  1419. /**
  1420. * @brief Insert an image in a worksheet cell.
  1421. *
  1422. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1423. * @param row The zero indexed row number.
  1424. * @param col The zero indexed column number.
  1425. * @param filename The image filename, with path if required.
  1426. *
  1427. * @return A #lxw_error code.
  1428. *
  1429. * This function can be used to insert a image into a worksheet. The image can
  1430. * be in PNG, JPEG or BMP format:
  1431. *
  1432. * @code
  1433. * worksheet_insert_image(worksheet, 2, 1, "logo.png");
  1434. * @endcode
  1435. *
  1436. * @image html insert_image.png
  1437. *
  1438. * The `worksheet_insert_image_opt()` function takes additional optional
  1439. * parameters to position and scale the image, see below.
  1440. *
  1441. * **Note**:
  1442. * The scaling of a image may be affected if is crosses a row that has its
  1443. * default height changed due to a font that is larger than the default font
  1444. * size or that has text wrapping turned on. To avoid this you should
  1445. * explicitly set the height of the row using `worksheet_set_row()` if it
  1446. * crosses an inserted image.
  1447. *
  1448. * BMP images are only supported for backward compatibility. In general it is
  1449. * best to avoid BMP images since they aren't compressed. If used, BMP images
  1450. * must be 24 bit, true color, bitmaps.
  1451. */
  1452. lxw_error worksheet_insert_image(lxw_worksheet *worksheet,
  1453. lxw_row_t row, lxw_col_t col,
  1454. const char *filename);
  1455. /**
  1456. * @brief Insert an image in a worksheet cell, with options.
  1457. *
  1458. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1459. * @param row The zero indexed row number.
  1460. * @param col The zero indexed column number.
  1461. * @param filename The image filename, with path if required.
  1462. * @param options Optional image parameters.
  1463. *
  1464. * @return A #lxw_error code.
  1465. *
  1466. * The `%worksheet_insert_image_opt()` function is like
  1467. * `worksheet_insert_image()` function except that it takes an optional
  1468. * #lxw_image_options struct to scale and position the image:
  1469. *
  1470. * @code
  1471. * lxw_image_options options = {.x_offset = 30, .y_offset = 10,
  1472. * .x_scale = 0.5, .y_scale = 0.5};
  1473. *
  1474. * worksheet_insert_image_opt(worksheet, 2, 1, "logo.png", &options);
  1475. *
  1476. * @endcode
  1477. *
  1478. * @image html insert_image_opt.png
  1479. *
  1480. * @note See the notes about row scaling and BMP images in
  1481. * `worksheet_insert_image()` above.
  1482. */
  1483. lxw_error worksheet_insert_image_opt(lxw_worksheet *worksheet,
  1484. lxw_row_t row, lxw_col_t col,
  1485. const char *filename,
  1486. lxw_image_options *options);
  1487. /**
  1488. * @brief Insert a chart object into a worksheet.
  1489. *
  1490. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1491. * @param row The zero indexed row number.
  1492. * @param col The zero indexed column number.
  1493. * @param chart A #lxw_chart object created via workbook_add_chart().
  1494. *
  1495. * @return A #lxw_error code.
  1496. *
  1497. * The `%worksheet_insert_chart()` can be used to insert a chart into a
  1498. * worksheet. The chart object must be created first using the
  1499. * `workbook_add_chart()` function and configured using the @ref chart.h
  1500. * functions.
  1501. *
  1502. * @code
  1503. * // Create a chart object.
  1504. * lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_LINE);
  1505. *
  1506. * // Add a data series to the chart.
  1507. * chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$6");
  1508. *
  1509. * // Insert the chart into the worksheet
  1510. * worksheet_insert_chart(worksheet, 0, 2, chart);
  1511. * @endcode
  1512. *
  1513. * @image html chart_working.png
  1514. *
  1515. *
  1516. * **Note:**
  1517. *
  1518. * A chart may only be inserted into a worksheet once. If several similar
  1519. * charts are required then each one must be created separately with
  1520. * `%worksheet_insert_chart()`.
  1521. *
  1522. */
  1523. lxw_error worksheet_insert_chart(lxw_worksheet *worksheet,
  1524. lxw_row_t row, lxw_col_t col,
  1525. lxw_chart *chart);
  1526. /**
  1527. * @brief Insert a chart object into a worksheet, with options.
  1528. *
  1529. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1530. * @param row The zero indexed row number.
  1531. * @param col The zero indexed column number.
  1532. * @param chart A #lxw_chart object created via workbook_add_chart().
  1533. * @param user_options Optional chart parameters.
  1534. *
  1535. * @return A #lxw_error code.
  1536. *
  1537. * The `%worksheet_insert_chart_opt()` function is like
  1538. * `worksheet_insert_chart()` function except that it takes an optional
  1539. * #lxw_image_options struct to scale and position the image of the chart:
  1540. *
  1541. * @code
  1542. * lxw_image_options options = {.x_offset = 30, .y_offset = 10,
  1543. * .x_scale = 0.5, .y_scale = 0.75};
  1544. *
  1545. * worksheet_insert_chart_opt(worksheet, 0, 2, chart, &options);
  1546. *
  1547. * @endcode
  1548. *
  1549. * @image html chart_line_opt.png
  1550. *
  1551. * The #lxw_image_options struct is the same struct used in
  1552. * `worksheet_insert_image_opt()` to position and scale images.
  1553. *
  1554. */
  1555. lxw_error worksheet_insert_chart_opt(lxw_worksheet *worksheet,
  1556. lxw_row_t row, lxw_col_t col,
  1557. lxw_chart *chart,
  1558. lxw_image_options *user_options);
  1559. /**
  1560. * @brief Merge a range of cells.
  1561. *
  1562. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1563. * @param first_row The first row of the range. (All zero indexed.)
  1564. * @param first_col The first column of the range.
  1565. * @param last_row The last row of the range.
  1566. * @param last_col The last col of the range.
  1567. * @param string String to write to the merged range.
  1568. * @param format A pointer to a Format instance or NULL.
  1569. *
  1570. * @return A #lxw_error code.
  1571. *
  1572. * The `%worksheet_merge_range()` function allows cells to be merged together
  1573. * so that they act as a single area.
  1574. *
  1575. * Excel generally merges and centers cells at same time. To get similar
  1576. * behavior with libxlsxwriter you need to apply a @ref format.h "Format"
  1577. * object with the appropriate alignment:
  1578. *
  1579. * @code
  1580. * lxw_format *merge_format = workbook_add_format(workbook);
  1581. * format_set_align(merge_format, LXW_ALIGN_CENTER);
  1582. *
  1583. * worksheet_merge_range(worksheet, 1, 1, 1, 3, "Merged Range", merge_format);
  1584. *
  1585. * @endcode
  1586. *
  1587. * It is possible to apply other formatting to the merged cells as well:
  1588. *
  1589. * @code
  1590. * format_set_align (merge_format, LXW_ALIGN_CENTER);
  1591. * format_set_align (merge_format, LXW_ALIGN_VERTICAL_CENTER);
  1592. * format_set_border (merge_format, LXW_BORDER_DOUBLE);
  1593. * format_set_bold (merge_format);
  1594. * format_set_bg_color(merge_format, 0xD7E4BC);
  1595. *
  1596. * worksheet_merge_range(worksheet, 2, 1, 3, 3, "Merged Range", merge_format);
  1597. *
  1598. * @endcode
  1599. *
  1600. * @image html merge.png
  1601. *
  1602. * The `%worksheet_merge_range()` function writes a `char*` string using
  1603. * `worksheet_write_string()`. In order to write other data types, such as a
  1604. * number or a formula, you can overwrite the first cell with a call to one of
  1605. * the other write functions. The same Format should be used as was used in
  1606. * the merged range.
  1607. *
  1608. * @code
  1609. * // First write a range with a blank string.
  1610. * worksheet_merge_range (worksheet, 1, 1, 1, 3, "", format);
  1611. *
  1612. * // Then overwrite the first cell with a number.
  1613. * worksheet_write_number(worksheet, 1, 1, 123, format);
  1614. * @endcode
  1615. *
  1616. * @note Merged ranges generally don’t work in libxlsxwriter when the Workbook
  1617. * #lxw_workbook_options `constant_memory` mode is enabled.
  1618. */
  1619. lxw_error worksheet_merge_range(lxw_worksheet *worksheet, lxw_row_t first_row,
  1620. lxw_col_t first_col, lxw_row_t last_row,
  1621. lxw_col_t last_col, const char *string,
  1622. lxw_format *format);
  1623. /**
  1624. * @brief Set the autofilter area in the worksheet.
  1625. *
  1626. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1627. * @param first_row The first row of the range. (All zero indexed.)
  1628. * @param first_col The first column of the range.
  1629. * @param last_row The last row of the range.
  1630. * @param last_col The last col of the range.
  1631. *
  1632. * @return A #lxw_error code.
  1633. *
  1634. * The `%worksheet_autofilter()` function allows an autofilter to be added to
  1635. * a worksheet.
  1636. *
  1637. * An autofilter is a way of adding drop down lists to the headers of a 2D
  1638. * range of worksheet data. This allows users to filter the data based on
  1639. * simple criteria so that some data is shown and some is hidden.
  1640. *
  1641. * @image html autofilter.png
  1642. *
  1643. * To add an autofilter to a worksheet:
  1644. *
  1645. * @code
  1646. * worksheet_autofilter(worksheet, 0, 0, 50, 3);
  1647. *
  1648. * // Same as above using the RANGE() macro.
  1649. * worksheet_autofilter(worksheet, RANGE("A1:D51"));
  1650. * @endcode
  1651. *
  1652. * Note: it isn't currently possible to apply filter conditions to the
  1653. * autofilter.
  1654. */
  1655. lxw_error worksheet_autofilter(lxw_worksheet *worksheet, lxw_row_t first_row,
  1656. lxw_col_t first_col, lxw_row_t last_row,
  1657. lxw_col_t last_col);
  1658. /**
  1659. * @brief Add a data validation to a cell.
  1660. *
  1661. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1662. * @param row The zero indexed row number.
  1663. * @param col The zero indexed column number.
  1664. * @param validation A #lxw_data_validation object to control the validation.
  1665. *
  1666. * @return A #lxw_error code.
  1667. *
  1668. * The `%worksheet_data_validation_cell()` function is used to construct an
  1669. * Excel data validation or to limit the user input to a dropdown list of
  1670. * values:
  1671. *
  1672. * @code
  1673. *
  1674. * lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
  1675. *
  1676. * data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
  1677. * data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
  1678. * data_validation->minimum_number = 1;
  1679. * data_validation->maximum_number = 10;
  1680. *
  1681. * worksheet_data_validation_cell(worksheet, 2, 1, data_validation);
  1682. *
  1683. * // Same as above with the CELL() macro.
  1684. * worksheet_data_validation_cell(worksheet, CELL("B3"), data_validation);
  1685. *
  1686. * @endcode
  1687. *
  1688. * @image html data_validate4.png
  1689. *
  1690. * Data validation and the various options of #lxw_data_validation are
  1691. * described in more detail in @ref working_with_data_validation.
  1692. */
  1693. lxw_error worksheet_data_validation_cell(lxw_worksheet *worksheet,
  1694. lxw_row_t row, lxw_col_t col,
  1695. lxw_data_validation *validation);
  1696. /**
  1697. * @brief Add a data validation to a range cell.
  1698. *
  1699. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1700. * @param first_row The first row of the range. (All zero indexed.)
  1701. * @param first_col The first column of the range.
  1702. * @param last_row The last row of the range.
  1703. * @param last_col The last col of the range.
  1704. * @param validation A #lxw_data_validation object to control the validation.
  1705. *
  1706. * @return A #lxw_error code.
  1707. *
  1708. * The `%worksheet_data_validation_range()` function is the same as the
  1709. * `%worksheet_data_validation_cell()`, see above, except the data validation
  1710. * is applied to a range of cells:
  1711. *
  1712. * @code
  1713. *
  1714. * lxw_data_validation *data_validation = calloc(1, sizeof(lxw_data_validation));
  1715. *
  1716. * data_validation->validate = LXW_VALIDATION_TYPE_INTEGER;
  1717. * data_validation->criteria = LXW_VALIDATION_CRITERIA_BETWEEN;
  1718. * data_validation->minimum_number = 1;
  1719. * data_validation->maximum_number = 10;
  1720. *
  1721. * worksheet_data_validation_range(worksheet, 2, 1, 4, 1, data_validation);
  1722. *
  1723. * // Same as above with the RANGE() macro.
  1724. * worksheet_data_validation_range(worksheet, RANGE("B3:B5"), data_validation);
  1725. *
  1726. * @endcode
  1727. *
  1728. * Data validation and the various options of #lxw_data_validation are
  1729. * described in more detail in @ref working_with_data_validation.
  1730. */
  1731. lxw_error worksheet_data_validation_range(lxw_worksheet *worksheet,
  1732. lxw_row_t first_row,
  1733. lxw_col_t first_col,
  1734. lxw_row_t last_row,
  1735. lxw_col_t last_col,
  1736. lxw_data_validation *validation);
  1737. /**
  1738. * @brief Make a worksheet the active, i.e., visible worksheet.
  1739. *
  1740. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1741. *
  1742. * The `%worksheet_activate()` function is used to specify which worksheet is
  1743. * initially visible in a multi-sheet workbook:
  1744. *
  1745. * @code
  1746. * lxw_worksheet *worksheet1 = workbook_add_worksheet(workbook, NULL);
  1747. * lxw_worksheet *worksheet2 = workbook_add_worksheet(workbook, NULL);
  1748. * lxw_worksheet *worksheet3 = workbook_add_worksheet(workbook, NULL);
  1749. *
  1750. * worksheet_activate(worksheet3);
  1751. * @endcode
  1752. *
  1753. * @image html worksheet_activate.png
  1754. *
  1755. * More than one worksheet can be selected via the `worksheet_select()`
  1756. * function, see below, however only one worksheet can be active.
  1757. *
  1758. * The default active worksheet is the first worksheet.
  1759. *
  1760. */
  1761. void worksheet_activate(lxw_worksheet *worksheet);
  1762. /**
  1763. * @brief Set a worksheet tab as selected.
  1764. *
  1765. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1766. *
  1767. * The `%worksheet_select()` function is used to indicate that a worksheet is
  1768. * selected in a multi-sheet workbook:
  1769. *
  1770. * @code
  1771. * worksheet_activate(worksheet1);
  1772. * worksheet_select(worksheet2);
  1773. * worksheet_select(worksheet3);
  1774. *
  1775. * @endcode
  1776. *
  1777. * A selected worksheet has its tab highlighted. Selecting worksheets is a
  1778. * way of grouping them together so that, for example, several worksheets
  1779. * could be printed in one go. A worksheet that has been activated via the
  1780. * `worksheet_activate()` function will also appear as selected.
  1781. *
  1782. */
  1783. void worksheet_select(lxw_worksheet *worksheet);
  1784. /**
  1785. * @brief Hide the current worksheet.
  1786. *
  1787. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1788. *
  1789. * The `%worksheet_hide()` function is used to hide a worksheet:
  1790. *
  1791. * @code
  1792. * worksheet_hide(worksheet2);
  1793. * @endcode
  1794. *
  1795. * You may wish to hide a worksheet in order to avoid confusing a user with
  1796. * intermediate data or calculations.
  1797. *
  1798. * @image html hide_sheet.png
  1799. *
  1800. * A hidden worksheet can not be activated or selected so this function is
  1801. * mutually exclusive with the `worksheet_activate()` and `worksheet_select()`
  1802. * functions. In addition, since the first worksheet will default to being the
  1803. * active worksheet, you cannot hide the first worksheet without activating
  1804. * another sheet:
  1805. *
  1806. * @code
  1807. * worksheet_activate(worksheet2);
  1808. * worksheet_hide(worksheet1);
  1809. * @endcode
  1810. */
  1811. void worksheet_hide(lxw_worksheet *worksheet);
  1812. /**
  1813. * @brief Set current worksheet as the first visible sheet tab.
  1814. *
  1815. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1816. *
  1817. * The `worksheet_activate()` function determines which worksheet is initially
  1818. * selected. However, if there are a large number of worksheets the selected
  1819. * worksheet may not appear on the screen. To avoid this you can select the
  1820. * leftmost visible worksheet tab using `%worksheet_set_first_sheet()`:
  1821. *
  1822. * @code
  1823. * worksheet_set_first_sheet(worksheet19); // First visible worksheet tab.
  1824. * worksheet_activate(worksheet20); // First visible worksheet.
  1825. * @endcode
  1826. *
  1827. * This function is not required very often. The default value is the first
  1828. * worksheet.
  1829. */
  1830. void worksheet_set_first_sheet(lxw_worksheet *worksheet);
  1831. /**
  1832. * @brief Split and freeze a worksheet into panes.
  1833. *
  1834. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1835. * @param row The cell row (zero indexed).
  1836. * @param col The cell column (zero indexed).
  1837. *
  1838. * The `%worksheet_freeze_panes()` function can be used to divide a worksheet
  1839. * into horizontal or vertical regions known as panes and to "freeze" these
  1840. * panes so that the splitter bars are not visible.
  1841. *
  1842. * The parameters `row` and `col` are used to specify the location of the
  1843. * split. It should be noted that the split is specified at the top or left of
  1844. * a cell and that the function uses zero based indexing. Therefore to freeze
  1845. * the first row of a worksheet it is necessary to specify the split at row 2
  1846. * (which is 1 as the zero-based index).
  1847. *
  1848. * You can set one of the `row` and `col` parameters as zero if you do not
  1849. * want either a vertical or horizontal split.
  1850. *
  1851. * Examples:
  1852. *
  1853. * @code
  1854. * worksheet_freeze_panes(worksheet1, 1, 0); // Freeze the first row.
  1855. * worksheet_freeze_panes(worksheet2, 0, 1); // Freeze the first column.
  1856. * worksheet_freeze_panes(worksheet3, 1, 1); // Freeze first row/column.
  1857. *
  1858. * @endcode
  1859. *
  1860. */
  1861. void worksheet_freeze_panes(lxw_worksheet *worksheet,
  1862. lxw_row_t row, lxw_col_t col);
  1863. /**
  1864. * @brief Split a worksheet into panes.
  1865. *
  1866. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1867. * @param vertical The position for the vertical split.
  1868. * @param horizontal The position for the horizontal split.
  1869. *
  1870. * The `%worksheet_split_panes()` function can be used to divide a worksheet
  1871. * into horizontal or vertical regions known as panes. This function is
  1872. * different from the `worksheet_freeze_panes()` function in that the splits
  1873. * between the panes will be visible to the user and each pane will have its
  1874. * own scroll bars.
  1875. *
  1876. * The parameters `vertical` and `horizontal` are used to specify the vertical
  1877. * and horizontal position of the split. The units for `vertical` and
  1878. * `horizontal` are the same as those used by Excel to specify row height and
  1879. * column width. However, the vertical and horizontal units are different from
  1880. * each other. Therefore you must specify the `vertical` and `horizontal`
  1881. * parameters in terms of the row heights and column widths that you have set
  1882. * or the default values which are 15 for a row and 8.43 for a column.
  1883. *
  1884. * Examples:
  1885. *
  1886. * @code
  1887. * worksheet_split_panes(worksheet1, 15, 0); // First row.
  1888. * worksheet_split_panes(worksheet2, 0, 8.43); // First column.
  1889. * worksheet_split_panes(worksheet3, 15, 8.43); // First row and column.
  1890. *
  1891. * @endcode
  1892. *
  1893. */
  1894. void worksheet_split_panes(lxw_worksheet *worksheet,
  1895. double vertical, double horizontal);
  1896. /* worksheet_freeze_panes() with infrequent options. Undocumented for now. */
  1897. void worksheet_freeze_panes_opt(lxw_worksheet *worksheet,
  1898. lxw_row_t first_row, lxw_col_t first_col,
  1899. lxw_row_t top_row, lxw_col_t left_col,
  1900. uint8_t type);
  1901. /* worksheet_split_panes() with infrequent options. Undocumented for now. */
  1902. void worksheet_split_panes_opt(lxw_worksheet *worksheet,
  1903. double vertical, double horizontal,
  1904. lxw_row_t top_row, lxw_col_t left_col);
  1905. /**
  1906. * @brief Set the selected cell or cells in a worksheet:
  1907. *
  1908. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1909. * @param first_row The first row of the range. (All zero indexed.)
  1910. * @param first_col The first column of the range.
  1911. * @param last_row The last row of the range.
  1912. * @param last_col The last col of the range.
  1913. *
  1914. *
  1915. * The `%worksheet_set_selection()` function can be used to specify which cell
  1916. * or range of cells is selected in a worksheet: The most common requirement
  1917. * is to select a single cell, in which case the `first_` and `last_`
  1918. * parameters should be the same.
  1919. *
  1920. * The active cell within a selected range is determined by the order in which
  1921. * `first_` and `last_` are specified.
  1922. *
  1923. * Examples:
  1924. *
  1925. * @code
  1926. * worksheet_set_selection(worksheet1, 3, 3, 3, 3); // Cell D4.
  1927. * worksheet_set_selection(worksheet2, 3, 3, 6, 6); // Cells D4 to G7.
  1928. * worksheet_set_selection(worksheet3, 6, 6, 3, 3); // Cells G7 to D4.
  1929. * worksheet_set_selection(worksheet5, RANGE("D4:G7")); // Using the RANGE macro.
  1930. *
  1931. * @endcode
  1932. *
  1933. */
  1934. void worksheet_set_selection(lxw_worksheet *worksheet,
  1935. lxw_row_t first_row, lxw_col_t first_col,
  1936. lxw_row_t last_row, lxw_col_t last_col);
  1937. /**
  1938. * @brief Set the page orientation as landscape.
  1939. *
  1940. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1941. *
  1942. * This function is used to set the orientation of a worksheet's printed page
  1943. * to landscape:
  1944. *
  1945. * @code
  1946. * worksheet_set_landscape(worksheet);
  1947. * @endcode
  1948. */
  1949. void worksheet_set_landscape(lxw_worksheet *worksheet);
  1950. /**
  1951. * @brief Set the page orientation as portrait.
  1952. *
  1953. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1954. *
  1955. * This function is used to set the orientation of a worksheet's printed page
  1956. * to portrait. The default worksheet orientation is portrait, so this
  1957. * function isn't generally required:
  1958. *
  1959. * @code
  1960. * worksheet_set_portrait(worksheet);
  1961. * @endcode
  1962. */
  1963. void worksheet_set_portrait(lxw_worksheet *worksheet);
  1964. /**
  1965. * @brief Set the page layout to page view mode.
  1966. *
  1967. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1968. *
  1969. * This function is used to display the worksheet in "Page View/Layout" mode:
  1970. *
  1971. * @code
  1972. * worksheet_set_page_view(worksheet);
  1973. * @endcode
  1974. */
  1975. void worksheet_set_page_view(lxw_worksheet *worksheet);
  1976. /**
  1977. * @brief Set the paper type for printing.
  1978. *
  1979. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  1980. * @param paper_type The Excel paper format type.
  1981. *
  1982. * This function is used to set the paper format for the printed output of a
  1983. * worksheet. The following paper styles are available:
  1984. *
  1985. *
  1986. * Index | Paper format | Paper size
  1987. * :------- | :---------------------- | :-------------------
  1988. * 0 | Printer default | Printer default
  1989. * 1 | Letter | 8 1/2 x 11 in
  1990. * 2 | Letter Small | 8 1/2 x 11 in
  1991. * 3 | Tabloid | 11 x 17 in
  1992. * 4 | Ledger | 17 x 11 in
  1993. * 5 | Legal | 8 1/2 x 14 in
  1994. * 6 | Statement | 5 1/2 x 8 1/2 in
  1995. * 7 | Executive | 7 1/4 x 10 1/2 in
  1996. * 8 | A3 | 297 x 420 mm
  1997. * 9 | A4 | 210 x 297 mm
  1998. * 10 | A4 Small | 210 x 297 mm
  1999. * 11 | A5 | 148 x 210 mm
  2000. * 12 | B4 | 250 x 354 mm
  2001. * 13 | B5 | 182 x 257 mm
  2002. * 14 | Folio | 8 1/2 x 13 in
  2003. * 15 | Quarto | 215 x 275 mm
  2004. * 16 | --- | 10x14 in
  2005. * 17 | --- | 11x17 in
  2006. * 18 | Note | 8 1/2 x 11 in
  2007. * 19 | Envelope 9 | 3 7/8 x 8 7/8
  2008. * 20 | Envelope 10 | 4 1/8 x 9 1/2
  2009. * 21 | Envelope 11 | 4 1/2 x 10 3/8
  2010. * 22 | Envelope 12 | 4 3/4 x 11
  2011. * 23 | Envelope 14 | 5 x 11 1/2
  2012. * 24 | C size sheet | ---
  2013. * 25 | D size sheet | ---
  2014. * 26 | E size sheet | ---
  2015. * 27 | Envelope DL | 110 x 220 mm
  2016. * 28 | Envelope C3 | 324 x 458 mm
  2017. * 29 | Envelope C4 | 229 x 324 mm
  2018. * 30 | Envelope C5 | 162 x 229 mm
  2019. * 31 | Envelope C6 | 114 x 162 mm
  2020. * 32 | Envelope C65 | 114 x 229 mm
  2021. * 33 | Envelope B4 | 250 x 353 mm
  2022. * 34 | Envelope B5 | 176 x 250 mm
  2023. * 35 | Envelope B6 | 176 x 125 mm
  2024. * 36 | Envelope | 110 x 230 mm
  2025. * 37 | Monarch | 3.875 x 7.5 in
  2026. * 38 | Envelope | 3 5/8 x 6 1/2 in
  2027. * 39 | Fanfold | 14 7/8 x 11 in
  2028. * 40 | German Std Fanfold | 8 1/2 x 12 in
  2029. * 41 | German Legal Fanfold | 8 1/2 x 13 in
  2030. *
  2031. * Note, it is likely that not all of these paper types will be available to
  2032. * the end user since it will depend on the paper formats that the user's
  2033. * printer supports. Therefore, it is best to stick to standard paper types:
  2034. *
  2035. * @code
  2036. * worksheet_set_paper(worksheet1, 1); // US Letter
  2037. * worksheet_set_paper(worksheet2, 9); // A4
  2038. * @endcode
  2039. *
  2040. * If you do not specify a paper type the worksheet will print using the
  2041. * printer's default paper style.
  2042. */
  2043. void worksheet_set_paper(lxw_worksheet *worksheet, uint8_t paper_type);
  2044. /**
  2045. * @brief Set the worksheet margins for the printed page.
  2046. *
  2047. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2048. * @param left Left margin in inches. Excel default is 0.7.
  2049. * @param right Right margin in inches. Excel default is 0.7.
  2050. * @param top Top margin in inches. Excel default is 0.75.
  2051. * @param bottom Bottom margin in inches. Excel default is 0.75.
  2052. *
  2053. * The `%worksheet_set_margins()` function is used to set the margins of the
  2054. * worksheet when it is printed. The units are in inches. Specifying `-1` for
  2055. * any parameter will give the default Excel value as shown above.
  2056. *
  2057. * @code
  2058. * worksheet_set_margins(worksheet, 1.3, 1.2, -1, -1);
  2059. * @endcode
  2060. *
  2061. */
  2062. void worksheet_set_margins(lxw_worksheet *worksheet, double left,
  2063. double right, double top, double bottom);
  2064. /**
  2065. * @brief Set the printed page header caption.
  2066. *
  2067. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2068. * @param string The header string.
  2069. *
  2070. * @return A #lxw_error code.
  2071. *
  2072. * Headers and footers are generated using a string which is a combination of
  2073. * plain text and control characters.
  2074. *
  2075. * The available control character are:
  2076. *
  2077. *
  2078. * | Control | Category | Description |
  2079. * | --------------- | ------------- | --------------------- |
  2080. * | `&L` | Justification | Left |
  2081. * | `&C` | | Center |
  2082. * | `&R` | | Right |
  2083. * | `&P` | Information | Page number |
  2084. * | `&N` | | Total number of pages |
  2085. * | `&D` | | Date |
  2086. * | `&T` | | Time |
  2087. * | `&F` | | File name |
  2088. * | `&A` | | Worksheet name |
  2089. * | `&Z` | | Workbook path |
  2090. * | `&fontsize` | Font | Font size |
  2091. * | `&"font,style"` | | Font name and style |
  2092. * | `&U` | | Single underline |
  2093. * | `&E` | | Double underline |
  2094. * | `&S` | | Strikethrough |
  2095. * | `&X` | | Superscript |
  2096. * | `&Y` | | Subscript |
  2097. *
  2098. *
  2099. * Text in headers and footers can be justified (aligned) to the left, center
  2100. * and right by prefixing the text with the control characters `&L`, `&C` and
  2101. * `&R`.
  2102. *
  2103. * For example (with ASCII art representation of the results):
  2104. *
  2105. * @code
  2106. * worksheet_set_header(worksheet, "&LHello");
  2107. *
  2108. * ---------------------------------------------------------------
  2109. * | |
  2110. * | Hello |
  2111. * | |
  2112. *
  2113. *
  2114. * worksheet_set_header(worksheet, "&CHello");
  2115. *
  2116. * ---------------------------------------------------------------
  2117. * | |
  2118. * | Hello |
  2119. * | |
  2120. *
  2121. *
  2122. * worksheet_set_header(worksheet, "&RHello");
  2123. *
  2124. * ---------------------------------------------------------------
  2125. * | |
  2126. * | Hello |
  2127. * | |
  2128. *
  2129. *
  2130. * @endcode
  2131. *
  2132. * For simple text, if you do not specify any justification the text will be
  2133. * centered. However, you must prefix the text with `&C` if you specify a font
  2134. * name or any other formatting:
  2135. *
  2136. * @code
  2137. * worksheet_set_header(worksheet, "Hello");
  2138. *
  2139. * ---------------------------------------------------------------
  2140. * | |
  2141. * | Hello |
  2142. * | |
  2143. *
  2144. * @endcode
  2145. *
  2146. * You can have text in each of the justification regions:
  2147. *
  2148. * @code
  2149. * worksheet_set_header(worksheet, "&LCiao&CBello&RCielo");
  2150. *
  2151. * ---------------------------------------------------------------
  2152. * | |
  2153. * | Ciao Bello Cielo |
  2154. * | |
  2155. *
  2156. * @endcode
  2157. *
  2158. * The information control characters act as variables that Excel will update
  2159. * as the workbook or worksheet changes. Times and dates are in the users
  2160. * default format:
  2161. *
  2162. * @code
  2163. * worksheet_set_header(worksheet, "&CPage &P of &N");
  2164. *
  2165. * ---------------------------------------------------------------
  2166. * | |
  2167. * | Page 1 of 6 |
  2168. * | |
  2169. *
  2170. * worksheet_set_header(worksheet, "&CUpdated at &T");
  2171. *
  2172. * ---------------------------------------------------------------
  2173. * | |
  2174. * | Updated at 12:30 PM |
  2175. * | |
  2176. *
  2177. * @endcode
  2178. *
  2179. * You can specify the font size of a section of the text by prefixing it with
  2180. * the control character `&n` where `n` is the font size:
  2181. *
  2182. * @code
  2183. * worksheet_set_header(worksheet1, "&C&30Hello Big");
  2184. * worksheet_set_header(worksheet2, "&C&10Hello Small");
  2185. *
  2186. * @endcode
  2187. *
  2188. * You can specify the font of a section of the text by prefixing it with the
  2189. * control sequence `&"font,style"` where `fontname` is a font name such as
  2190. * Windows font descriptions: "Regular", "Italic", "Bold" or "Bold Italic":
  2191. * "Courier New" or "Times New Roman" and `style` is one of the standard
  2192. *
  2193. * @code
  2194. * worksheet_set_header(worksheet1, "&C&\"Courier New,Italic\"Hello");
  2195. * worksheet_set_header(worksheet2, "&C&\"Courier New,Bold Italic\"Hello");
  2196. * worksheet_set_header(worksheet3, "&C&\"Times New Roman,Regular\"Hello");
  2197. *
  2198. * @endcode
  2199. *
  2200. * It is possible to combine all of these features together to create
  2201. * sophisticated headers and footers. As an aid to setting up complicated
  2202. * headers and footers you can record a page set-up as a macro in Excel and
  2203. * look at the format strings that VBA produces. Remember however that VBA
  2204. * uses two double quotes `""` to indicate a single double quote. For the last
  2205. * example above the equivalent VBA code looks like this:
  2206. *
  2207. * @code
  2208. * .LeftHeader = ""
  2209. * .CenterHeader = "&""Times New Roman,Regular""Hello"
  2210. * .RightHeader = ""
  2211. *
  2212. * @endcode
  2213. *
  2214. * Alternatively you can inspect the header and footer strings in an Excel
  2215. * file by unzipping it and grepping the XML sub-files. The following shows
  2216. * how to do that using libxml's xmllint to format the XML for clarity:
  2217. *
  2218. * @code
  2219. *
  2220. * $ unzip myfile.xlsm -d myfile
  2221. * $ xmllint --format `find myfile -name "*.xml" | xargs` | egrep "Header|Footer"
  2222. *
  2223. * <headerFooter scaleWithDoc="0">
  2224. * <oddHeader>&amp;L&amp;P</oddHeader>
  2225. * </headerFooter>
  2226. *
  2227. * @endcode
  2228. *
  2229. * Note that in this case you need to unescape the Html. In the above example
  2230. * the header string would be `&L&P`.
  2231. *
  2232. * To include a single literal ampersand `&` in a header or footer you should
  2233. * use a double ampersand `&&`:
  2234. *
  2235. * @code
  2236. * worksheet_set_header(worksheet, "&CCuriouser && Curiouser - Attorneys at Law");
  2237. * @endcode
  2238. *
  2239. * Note, the header or footer string must be less than 255 characters. Strings
  2240. * longer than this will not be written.
  2241. *
  2242. */
  2243. lxw_error worksheet_set_header(lxw_worksheet *worksheet, const char *string);
  2244. /**
  2245. * @brief Set the printed page footer caption.
  2246. *
  2247. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2248. * @param string The footer string.
  2249. *
  2250. * @return A #lxw_error code.
  2251. *
  2252. * The syntax of this function is the same as worksheet_set_header().
  2253. *
  2254. */
  2255. lxw_error worksheet_set_footer(lxw_worksheet *worksheet, const char *string);
  2256. /**
  2257. * @brief Set the printed page header caption with additional options.
  2258. *
  2259. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2260. * @param string The header string.
  2261. * @param options Header options.
  2262. *
  2263. * @return A #lxw_error code.
  2264. *
  2265. * The syntax of this function is the same as worksheet_set_header() with an
  2266. * additional parameter to specify options for the header.
  2267. *
  2268. * Currently, the only available option is the header margin:
  2269. *
  2270. * @code
  2271. *
  2272. * lxw_header_footer_options header_options = { 0.2 };
  2273. *
  2274. * worksheet_set_header_opt(worksheet, "Some text", &header_options);
  2275. *
  2276. * @endcode
  2277. *
  2278. */
  2279. lxw_error worksheet_set_header_opt(lxw_worksheet *worksheet,
  2280. const char *string,
  2281. lxw_header_footer_options *options);
  2282. /**
  2283. * @brief Set the printed page footer caption with additional options.
  2284. *
  2285. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2286. * @param string The footer string.
  2287. * @param options Footer options.
  2288. *
  2289. * @return A #lxw_error code.
  2290. *
  2291. * The syntax of this function is the same as worksheet_set_header_opt().
  2292. *
  2293. */
  2294. lxw_error worksheet_set_footer_opt(lxw_worksheet *worksheet,
  2295. const char *string,
  2296. lxw_header_footer_options *options);
  2297. /**
  2298. * @brief Set the horizontal page breaks on a worksheet.
  2299. *
  2300. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2301. * @param breaks Array of page breaks.
  2302. *
  2303. * @return A #lxw_error code.
  2304. *
  2305. * The `%worksheet_set_h_pagebreaks()` function adds horizontal page breaks to
  2306. * a worksheet. A page break causes all the data that follows it to be printed
  2307. * on the next page. Horizontal page breaks act between rows.
  2308. *
  2309. * The function takes an array of one or more page breaks. The type of the
  2310. * array data is @ref lxw_row_t and the last element of the array must be 0:
  2311. *
  2312. * @code
  2313. * lxw_row_t breaks1[] = {20, 0}; // 1 page break. Zero indicates the end.
  2314. * lxw_row_t breaks2[] = {20, 40, 60, 80, 0};
  2315. *
  2316. * worksheet_set_h_pagebreaks(worksheet1, breaks1);
  2317. * worksheet_set_h_pagebreaks(worksheet2, breaks2);
  2318. * @endcode
  2319. *
  2320. * To create a page break between rows 20 and 21 you must specify the break at
  2321. * row 21. However in zero index notation this is actually row 20:
  2322. *
  2323. * @code
  2324. * // Break between row 20 and 21.
  2325. * lxw_row_t breaks[] = {20, 0};
  2326. *
  2327. * worksheet_set_h_pagebreaks(worksheet, breaks);
  2328. * @endcode
  2329. *
  2330. * There is an Excel limitation of 1023 horizontal page breaks per worksheet.
  2331. *
  2332. * Note: If you specify the "fit to page" option via the
  2333. * `worksheet_fit_to_pages()` function it will override all manual page
  2334. * breaks.
  2335. *
  2336. */
  2337. lxw_error worksheet_set_h_pagebreaks(lxw_worksheet *worksheet,
  2338. lxw_row_t breaks[]);
  2339. /**
  2340. * @brief Set the vertical page breaks on a worksheet.
  2341. *
  2342. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2343. * @param breaks Array of page breaks.
  2344. *
  2345. * @return A #lxw_error code.
  2346. *
  2347. * The `%worksheet_set_v_pagebreaks()` function adds vertical page breaks to a
  2348. * worksheet. A page break causes all the data that follows it to be printed
  2349. * on the next page. Vertical page breaks act between columns.
  2350. *
  2351. * The function takes an array of one or more page breaks. The type of the
  2352. * array data is @ref lxw_col_t and the last element of the array must be 0:
  2353. *
  2354. * @code
  2355. * lxw_col_t breaks1[] = {20, 0}; // 1 page break. Zero indicates the end.
  2356. * lxw_col_t breaks2[] = {20, 40, 60, 80, 0};
  2357. *
  2358. * worksheet_set_v_pagebreaks(worksheet1, breaks1);
  2359. * worksheet_set_v_pagebreaks(worksheet2, breaks2);
  2360. * @endcode
  2361. *
  2362. * To create a page break between columns 20 and 21 you must specify the break
  2363. * at column 21. However in zero index notation this is actually column 20:
  2364. *
  2365. * @code
  2366. * // Break between column 20 and 21.
  2367. * lxw_col_t breaks[] = {20, 0};
  2368. *
  2369. * worksheet_set_v_pagebreaks(worksheet, breaks);
  2370. * @endcode
  2371. *
  2372. * There is an Excel limitation of 1023 vertical page breaks per worksheet.
  2373. *
  2374. * Note: If you specify the "fit to page" option via the
  2375. * `worksheet_fit_to_pages()` function it will override all manual page
  2376. * breaks.
  2377. *
  2378. */
  2379. lxw_error worksheet_set_v_pagebreaks(lxw_worksheet *worksheet,
  2380. lxw_col_t breaks[]);
  2381. /**
  2382. * @brief Set the order in which pages are printed.
  2383. *
  2384. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2385. *
  2386. * The `%worksheet_print_across()` function is used to change the default
  2387. * print direction. This is referred to by Excel as the sheet "page order":
  2388. *
  2389. * @code
  2390. * worksheet_print_across(worksheet);
  2391. * @endcode
  2392. *
  2393. * The default page order is shown below for a worksheet that extends over 4
  2394. * pages. The order is called "down then across":
  2395. *
  2396. * [1] [3]
  2397. * [2] [4]
  2398. *
  2399. * However, by using the `print_across` function the print order will be
  2400. * changed to "across then down":
  2401. *
  2402. * [1] [2]
  2403. * [3] [4]
  2404. *
  2405. */
  2406. void worksheet_print_across(lxw_worksheet *worksheet);
  2407. /**
  2408. * @brief Set the worksheet zoom factor.
  2409. *
  2410. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2411. * @param scale Worksheet zoom factor.
  2412. *
  2413. * Set the worksheet zoom factor in the range `10 <= zoom <= 400`:
  2414. *
  2415. * @code
  2416. * worksheet_set_zoom(worksheet1, 50);
  2417. * worksheet_set_zoom(worksheet2, 75);
  2418. * worksheet_set_zoom(worksheet3, 300);
  2419. * worksheet_set_zoom(worksheet4, 400);
  2420. * @endcode
  2421. *
  2422. * The default zoom factor is 100. It isn't possible to set the zoom to
  2423. * "Selection" because it is calculated by Excel at run-time.
  2424. *
  2425. * Note, `%worksheet_zoom()` does not affect the scale of the printed
  2426. * page. For that you should use `worksheet_set_print_scale()`.
  2427. */
  2428. void worksheet_set_zoom(lxw_worksheet *worksheet, uint16_t scale);
  2429. /**
  2430. * @brief Set the option to display or hide gridlines on the screen and
  2431. * the printed page.
  2432. *
  2433. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2434. * @param option Gridline option.
  2435. *
  2436. * Display or hide screen and print gridlines using one of the values of
  2437. * @ref lxw_gridlines.
  2438. *
  2439. * @code
  2440. * worksheet_gridlines(worksheet1, LXW_HIDE_ALL_GRIDLINES);
  2441. *
  2442. * worksheet_gridlines(worksheet2, LXW_SHOW_PRINT_GRIDLINES);
  2443. * @endcode
  2444. *
  2445. * The Excel default is that the screen gridlines are on and the printed
  2446. * worksheet is off.
  2447. *
  2448. */
  2449. void worksheet_gridlines(lxw_worksheet *worksheet, uint8_t option);
  2450. /**
  2451. * @brief Center the printed page horizontally.
  2452. *
  2453. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2454. *
  2455. * Center the worksheet data horizontally between the margins on the printed
  2456. * page:
  2457. *
  2458. * @code
  2459. * worksheet_center_horizontally(worksheet);
  2460. * @endcode
  2461. *
  2462. */
  2463. void worksheet_center_horizontally(lxw_worksheet *worksheet);
  2464. /**
  2465. * @brief Center the printed page vertically.
  2466. *
  2467. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2468. *
  2469. * Center the worksheet data vertically between the margins on the printed
  2470. * page:
  2471. *
  2472. * @code
  2473. * worksheet_center_vertically(worksheet);
  2474. * @endcode
  2475. *
  2476. */
  2477. void worksheet_center_vertically(lxw_worksheet *worksheet);
  2478. /**
  2479. * @brief Set the option to print the row and column headers on the printed
  2480. * page.
  2481. *
  2482. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2483. *
  2484. * When printing a worksheet from Excel the row and column headers (the row
  2485. * numbers on the left and the column letters at the top) aren't printed by
  2486. * default.
  2487. *
  2488. * This function sets the printer option to print these headers:
  2489. *
  2490. * @code
  2491. * worksheet_print_row_col_headers(worksheet);
  2492. * @endcode
  2493. *
  2494. */
  2495. void worksheet_print_row_col_headers(lxw_worksheet *worksheet);
  2496. /**
  2497. * @brief Set the number of rows to repeat at the top of each printed page.
  2498. *
  2499. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2500. * @param first_row First row of repeat range.
  2501. * @param last_row Last row of repeat range.
  2502. *
  2503. * @return A #lxw_error code.
  2504. *
  2505. * For large Excel documents it is often desirable to have the first row or
  2506. * rows of the worksheet print out at the top of each page.
  2507. *
  2508. * This can be achieved by using this function. The parameters `first_row`
  2509. * and `last_row` are zero based:
  2510. *
  2511. * @code
  2512. * worksheet_repeat_rows(worksheet, 0, 0); // Repeat the first row.
  2513. * worksheet_repeat_rows(worksheet, 0, 1); // Repeat the first two rows.
  2514. * @endcode
  2515. */
  2516. lxw_error worksheet_repeat_rows(lxw_worksheet *worksheet, lxw_row_t first_row,
  2517. lxw_row_t last_row);
  2518. /**
  2519. * @brief Set the number of columns to repeat at the top of each printed page.
  2520. *
  2521. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2522. * @param first_col First column of repeat range.
  2523. * @param last_col Last column of repeat range.
  2524. *
  2525. * @return A #lxw_error code.
  2526. *
  2527. * For large Excel documents it is often desirable to have the first column or
  2528. * columns of the worksheet print out at the left of each page.
  2529. *
  2530. * This can be achieved by using this function. The parameters `first_col`
  2531. * and `last_col` are zero based:
  2532. *
  2533. * @code
  2534. * worksheet_repeat_columns(worksheet, 0, 0); // Repeat the first col.
  2535. * worksheet_repeat_columns(worksheet, 0, 1); // Repeat the first two cols.
  2536. * @endcode
  2537. */
  2538. lxw_error worksheet_repeat_columns(lxw_worksheet *worksheet,
  2539. lxw_col_t first_col, lxw_col_t last_col);
  2540. /**
  2541. * @brief Set the print area for a worksheet.
  2542. *
  2543. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2544. * @param first_row The first row of the range. (All zero indexed.)
  2545. * @param first_col The first column of the range.
  2546. * @param last_row The last row of the range.
  2547. * @param last_col The last col of the range.
  2548. *
  2549. * @return A #lxw_error code.
  2550. *
  2551. * This function is used to specify the area of the worksheet that will be
  2552. * printed. The RANGE() macro is often convenient for this.
  2553. *
  2554. * @code
  2555. * worksheet_print_area(worksheet, 0, 0, 41, 10); // A1:K42.
  2556. *
  2557. * // Same as:
  2558. * worksheet_print_area(worksheet, RANGE("A1:K42"));
  2559. * @endcode
  2560. *
  2561. * In order to set a row or column range you must specify the entire range:
  2562. *
  2563. * @code
  2564. * worksheet_print_area(worksheet, RANGE("A1:H1048576")); // Same as A:H.
  2565. * @endcode
  2566. */
  2567. lxw_error worksheet_print_area(lxw_worksheet *worksheet, lxw_row_t first_row,
  2568. lxw_col_t first_col, lxw_row_t last_row,
  2569. lxw_col_t last_col);
  2570. /**
  2571. * @brief Fit the printed area to a specific number of pages both vertically
  2572. * and horizontally.
  2573. *
  2574. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2575. * @param width Number of pages horizontally.
  2576. * @param height Number of pages vertically.
  2577. *
  2578. * The `%worksheet_fit_to_pages()` function is used to fit the printed area to
  2579. * a specific number of pages both vertically and horizontally. If the printed
  2580. * area exceeds the specified number of pages it will be scaled down to
  2581. * fit. This ensures that the printed area will always appear on the specified
  2582. * number of pages even if the page size or margins change:
  2583. *
  2584. * @code
  2585. * worksheet_fit_to_pages(worksheet1, 1, 1); // Fit to 1x1 pages.
  2586. * worksheet_fit_to_pages(worksheet2, 2, 1); // Fit to 2x1 pages.
  2587. * worksheet_fit_to_pages(worksheet3, 1, 2); // Fit to 1x2 pages.
  2588. * @endcode
  2589. *
  2590. * The print area can be defined using the `worksheet_print_area()` function
  2591. * as described above.
  2592. *
  2593. * A common requirement is to fit the printed output to `n` pages wide but
  2594. * have the height be as long as necessary. To achieve this set the `height`
  2595. * to zero:
  2596. *
  2597. * @code
  2598. * // 1 page wide and as long as necessary.
  2599. * worksheet_fit_to_pages(worksheet, 1, 0);
  2600. * @endcode
  2601. *
  2602. * **Note**:
  2603. *
  2604. * - Although it is valid to use both `%worksheet_fit_to_pages()` and
  2605. * `worksheet_set_print_scale()` on the same worksheet Excel only allows one
  2606. * of these options to be active at a time. The last function call made will
  2607. * set the active option.
  2608. *
  2609. * - The `%worksheet_fit_to_pages()` function will override any manual page
  2610. * breaks that are defined in the worksheet.
  2611. *
  2612. * - When using `%worksheet_fit_to_pages()` it may also be required to set the
  2613. * printer paper size using `worksheet_set_paper()` or else Excel will
  2614. * default to "US Letter".
  2615. *
  2616. */
  2617. void worksheet_fit_to_pages(lxw_worksheet *worksheet, uint16_t width,
  2618. uint16_t height);
  2619. /**
  2620. * @brief Set the start page number when printing.
  2621. *
  2622. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2623. * @param start_page Starting page number.
  2624. *
  2625. * The `%worksheet_set_start_page()` function is used to set the number of
  2626. * the starting page when the worksheet is printed out:
  2627. *
  2628. * @code
  2629. * // Start print from page 2.
  2630. * worksheet_set_start_page(worksheet, 2);
  2631. * @endcode
  2632. */
  2633. void worksheet_set_start_page(lxw_worksheet *worksheet, uint16_t start_page);
  2634. /**
  2635. * @brief Set the scale factor for the printed page.
  2636. *
  2637. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2638. * @param scale Print scale of worksheet to be printed.
  2639. *
  2640. * This function sets the scale factor of the printed page. The Scale factor
  2641. * must be in the range `10 <= scale <= 400`:
  2642. *
  2643. * @code
  2644. * worksheet_set_print_scale(worksheet1, 75);
  2645. * worksheet_set_print_scale(worksheet2, 400);
  2646. * @endcode
  2647. *
  2648. * The default scale factor is 100. Note, `%worksheet_set_print_scale()` does
  2649. * not affect the scale of the visible page in Excel. For that you should use
  2650. * `worksheet_set_zoom()`.
  2651. *
  2652. * Note that although it is valid to use both `worksheet_fit_to_pages()` and
  2653. * `%worksheet_set_print_scale()` on the same worksheet Excel only allows one
  2654. * of these options to be active at a time. The last function call made will
  2655. * set the active option.
  2656. *
  2657. */
  2658. void worksheet_set_print_scale(lxw_worksheet *worksheet, uint16_t scale);
  2659. /**
  2660. * @brief Display the worksheet cells from right to left for some versions of
  2661. * Excel.
  2662. *
  2663. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2664. *
  2665. * The `%worksheet_right_to_left()` function is used to change the default
  2666. * direction of the worksheet from left-to-right, with the `A1` cell in the
  2667. * top left, to right-to-left, with the `A1` cell in the top right.
  2668. *
  2669. * @code
  2670. * worksheet_right_to_left(worksheet1);
  2671. * @endcode
  2672. *
  2673. * This is useful when creating Arabic, Hebrew or other near or far eastern
  2674. * worksheets that use right-to-left as the default direction.
  2675. */
  2676. void worksheet_right_to_left(lxw_worksheet *worksheet);
  2677. /**
  2678. * @brief Hide zero values in worksheet cells.
  2679. *
  2680. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2681. *
  2682. * The `%worksheet_hide_zero()` function is used to hide any zero values that
  2683. * appear in cells:
  2684. *
  2685. * @code
  2686. * worksheet_hide_zero(worksheet1);
  2687. * @endcode
  2688. */
  2689. void worksheet_hide_zero(lxw_worksheet *worksheet);
  2690. /**
  2691. * @brief Set the color of the worksheet tab.
  2692. *
  2693. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2694. * @param color The tab color.
  2695. *
  2696. * The `%worksheet_set_tab_color()` function is used to change the color of the worksheet
  2697. * tab:
  2698. *
  2699. * @code
  2700. * worksheet_set_tab_color(worksheet1, LXW_COLOR_RED);
  2701. * worksheet_set_tab_color(worksheet2, LXW_COLOR_GREEN);
  2702. * worksheet_set_tab_color(worksheet3, 0xFF9900); // Orange.
  2703. * @endcode
  2704. *
  2705. * The color should be an RGB integer value, see @ref working_with_colors.
  2706. */
  2707. void worksheet_set_tab_color(lxw_worksheet *worksheet, lxw_color_t color);
  2708. /**
  2709. * @brief Protect elements of a worksheet from modification.
  2710. *
  2711. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2712. * @param password A worksheet password.
  2713. * @param options Worksheet elements to protect.
  2714. *
  2715. * The `%worksheet_protect()` function protects worksheet elements from modification:
  2716. *
  2717. * @code
  2718. * worksheet_protect(worksheet, "Some Password", options);
  2719. * @endcode
  2720. *
  2721. * The `password` and lxw_protection pointer are both optional:
  2722. *
  2723. * @code
  2724. * worksheet_protect(worksheet1, NULL, NULL);
  2725. * worksheet_protect(worksheet2, NULL, my_options);
  2726. * worksheet_protect(worksheet3, "password", NULL);
  2727. * worksheet_protect(worksheet4, "password", my_options);
  2728. * @endcode
  2729. *
  2730. * Passing a `NULL` password is the same as turning on protection without a
  2731. * password. Passing a `NULL` password and `NULL` options, or any other
  2732. * combination has the effect of enabling a cell's `locked` and `hidden`
  2733. * properties if they have been set.
  2734. *
  2735. * A *locked* cell cannot be edited and this property is on by default for all
  2736. * cells. A *hidden* cell will display the results of a formula but not the
  2737. * formula itself. These properties can be set using the format_set_unlocked()
  2738. * and format_set_hidden() format functions.
  2739. *
  2740. * You can specify which worksheet elements you wish to protect by passing a
  2741. * lxw_protection pointer in the `options` argument with any or all of the
  2742. * following members set:
  2743. *
  2744. * no_select_locked_cells
  2745. * no_select_unlocked_cells
  2746. * format_cells
  2747. * format_columns
  2748. * format_rows
  2749. * insert_columns
  2750. * insert_rows
  2751. * insert_hyperlinks
  2752. * delete_columns
  2753. * delete_rows
  2754. * sort
  2755. * autofilter
  2756. * pivot_tables
  2757. * scenarios
  2758. * objects
  2759. *
  2760. * All parameters are off by default. Individual elements can be protected as
  2761. * follows:
  2762. *
  2763. * @code
  2764. * lxw_protection options = {
  2765. * .format_cells = 1,
  2766. * .insert_hyperlinks = 1,
  2767. * .insert_rows = 1,
  2768. * .delete_rows = 1,
  2769. * .insert_columns = 1,
  2770. * .delete_columns = 1,
  2771. * };
  2772. *
  2773. * worksheet_protect(worksheet, NULL, &options);
  2774. *
  2775. * @endcode
  2776. *
  2777. * See also the format_set_unlocked() and format_set_hidden() format functions.
  2778. *
  2779. * **Note:** Worksheet level passwords in Excel offer **very** weak
  2780. * protection. They don't encrypt your data and are very easy to
  2781. * deactivate. Full workbook encryption is not supported by `libxlsxwriter`
  2782. * since it requires a completely different file format and would take several
  2783. * man months to implement.
  2784. */
  2785. void worksheet_protect(lxw_worksheet *worksheet, const char *password,
  2786. lxw_protection *options);
  2787. /**
  2788. * @brief Set the Outline and Grouping display properties.
  2789. *
  2790. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2791. * @param visible Outlines are visible. Optional, defaults to True.
  2792. * @param symbols_below Show row outline symbols below the outline bar.
  2793. * @param symbols_right Show column outline symbols to the right of outline.
  2794. * @param auto_style Use Automatic outline style.
  2795. *
  2796. * The `%worksheet_outline_settings()` method is used to control the
  2797. * appearance of outlines in Excel. Outlines are described the section on
  2798. * @ref working_with_outlines.
  2799. *
  2800. * The `visible` parameter is used to control whether or not outlines are
  2801. * visible. Setting this parameter to False will cause all outlines on the
  2802. * worksheet to be hidden. They can be un-hidden in Excel by means of the
  2803. * "Show Outline Symbols" command button. The default Excel setting is True
  2804. * for visible outlines.
  2805. *
  2806. * The `symbols_below` parameter is used to control whether the row outline
  2807. * symbol will appear above or below the outline level bar. The default Excel
  2808. * setting is True for symbols to appear below the outline level bar.
  2809. *
  2810. * The `symbols_right` parameter is used to control whether the column outline
  2811. * symbol will appear to the left or the right of the outline level bar. The
  2812. * default Excel setting is True for symbols to appear to the right of the
  2813. * outline level bar.
  2814. *
  2815. * The `auto_style` parameter is used to control whether the automatic outline
  2816. * generator in Excel uses automatic styles when creating an outline. This has
  2817. * no effect on a file generated by XlsxWriter but it does have an effect on
  2818. * how the worksheet behaves after it is created. The default Excel setting is
  2819. * False for "Automatic Styles" to be turned off.
  2820. *
  2821. * The default settings for all of these parameters in libxlsxwriter
  2822. * correspond to Excel's default parameters and are shown below:
  2823. *
  2824. * @code
  2825. * worksheet_outline_settings(worksheet1, LXW_TRUE, LXW_TRUE, LXW_TRUE, LXW_FALSE);
  2826. * @endcode
  2827. *
  2828. * The worksheet parameters controlled by `worksheet_outline_settings()` are
  2829. * rarely used.
  2830. */
  2831. void worksheet_outline_settings(lxw_worksheet *worksheet, uint8_t visible,
  2832. uint8_t symbols_below, uint8_t symbols_right,
  2833. uint8_t auto_style);
  2834. /**
  2835. * @brief Set the default row properties.
  2836. *
  2837. * @param worksheet Pointer to a lxw_worksheet instance to be updated.
  2838. * @param height Default row height.
  2839. * @param hide_unused_rows Hide unused cells.
  2840. *
  2841. * The `%worksheet_set_default_row()` function is used to set Excel default
  2842. * row properties such as the default height and the option to hide unused
  2843. * rows. These parameters are an optimization used by Excel to set row
  2844. * properties without generating a very large file with an entry for each row.
  2845. *
  2846. * To set the default row height:
  2847. *
  2848. * @code
  2849. * worksheet_set_default_row(worksheet, 24, LXW_FALSE);
  2850. *
  2851. * @endcode
  2852. *
  2853. * To hide unused rows:
  2854. *
  2855. * @code
  2856. * worksheet_set_default_row(worksheet, 15, LXW_TRUE);
  2857. * @endcode
  2858. *
  2859. * Note, in the previous case we use the default height #LXW_DEF_ROW_HEIGHT =
  2860. * 15 so the the height remains unchanged.
  2861. */
  2862. void worksheet_set_default_row(lxw_worksheet *worksheet, double height,
  2863. uint8_t hide_unused_rows);
  2864. lxw_worksheet *lxw_worksheet_new(lxw_worksheet_init_data *init_data);
  2865. void lxw_worksheet_free(lxw_worksheet *worksheet);
  2866. void lxw_worksheet_assemble_xml_file(lxw_worksheet *worksheet);
  2867. void lxw_worksheet_write_single_row(lxw_worksheet *worksheet);
  2868. void lxw_worksheet_prepare_image(lxw_worksheet *worksheet,
  2869. uint16_t image_ref_id, uint16_t drawing_id,
  2870. lxw_image_options *image_data);
  2871. void lxw_worksheet_prepare_chart(lxw_worksheet *worksheet,
  2872. uint16_t chart_ref_id, uint16_t drawing_id,
  2873. lxw_image_options *image_data);
  2874. lxw_row *lxw_worksheet_find_row(lxw_worksheet *worksheet, lxw_row_t row_num);
  2875. lxw_cell *lxw_worksheet_find_cell(lxw_row *row, lxw_col_t col_num);
  2876. /* Declarations required for unit testing. */
  2877. #ifdef TESTING
  2878. STATIC void _worksheet_xml_declaration(lxw_worksheet *worksheet);
  2879. STATIC void _worksheet_write_worksheet(lxw_worksheet *worksheet);
  2880. STATIC void _worksheet_write_dimension(lxw_worksheet *worksheet);
  2881. STATIC void _worksheet_write_sheet_view(lxw_worksheet *worksheet);
  2882. STATIC void _worksheet_write_sheet_views(lxw_worksheet *worksheet);
  2883. STATIC void _worksheet_write_sheet_format_pr(lxw_worksheet *worksheet);
  2884. STATIC void _worksheet_write_sheet_data(lxw_worksheet *worksheet);
  2885. STATIC void _worksheet_write_page_margins(lxw_worksheet *worksheet);
  2886. STATIC void _worksheet_write_page_setup(lxw_worksheet *worksheet);
  2887. STATIC void _worksheet_write_col_info(lxw_worksheet *worksheet,
  2888. lxw_col_options *options);
  2889. STATIC void _write_row(lxw_worksheet *worksheet, lxw_row *row, char *spans);
  2890. STATIC lxw_row *_get_row_list(struct lxw_table_rows *table,
  2891. lxw_row_t row_num);
  2892. STATIC void _worksheet_write_merge_cell(lxw_worksheet *worksheet,
  2893. lxw_merged_range *merged_range);
  2894. STATIC void _worksheet_write_merge_cells(lxw_worksheet *worksheet);
  2895. STATIC void _worksheet_write_odd_header(lxw_worksheet *worksheet);
  2896. STATIC void _worksheet_write_odd_footer(lxw_worksheet *worksheet);
  2897. STATIC void _worksheet_write_header_footer(lxw_worksheet *worksheet);
  2898. STATIC void _worksheet_write_print_options(lxw_worksheet *worksheet);
  2899. STATIC void _worksheet_write_sheet_pr(lxw_worksheet *worksheet);
  2900. STATIC void _worksheet_write_tab_color(lxw_worksheet *worksheet);
  2901. STATIC void _worksheet_write_sheet_protection(lxw_worksheet *worksheet);
  2902. STATIC void _worksheet_write_data_validations(lxw_worksheet *self);
  2903. #endif /* TESTING */
  2904. /* *INDENT-OFF* */
  2905. #ifdef __cplusplus
  2906. }
  2907. #endif
  2908. /* *INDENT-ON* */
  2909. #endif /* __LXW_WORKSHEET_H__ */